What is the best way to create sequential row numbers (1, 2, 3, ...) while combining a custom table with an array?

In our project using Vue.js, we have implemented a custom table bound to an array. It is visualized as shown below:

https://i.sstatic.net/FlXCF.png

The crucial part of the HTML code appears like this:

<InfiniteScroll ref="scroller" :disable="finished" @load="onLoad">
  <swipeable-table
    v-if="waitingList.length"
    :headers="headers"
    :items="waitingList"
    :loading="loading"
    custom-width
    outerBorder
  >
    <template slot="rows" slot-scope="{ item: booking }">
      <tr>
        <td>{{ 0 }}</td>
        <td></td>
        <td></td>
        <td>{{ fullName(booking.user) }}</td>
        <td>{{ unitName(booking.search_by) }}</td>
        ...
      </tr>
    </template>
  </swipeable-table>
  ...
</InfiniteScroll>

The array waitingList consists of objects.

This snippet of JavaScript code is depicted as follows:

methods: {
  fullName(user) {
    return fullName.by(user, null, true)
  },
  unitName(unit) {
    return unit?.name ?? ''
  },
  ...

The table has infinite scrolling functionality, displaying 30 items initially and loading the next set of 30 items as you scroll (e.g., 30+30=60).

The object array looks similar to the images displayed here: https://i.sstatic.net/8vEjQ.png, https://i.sstatic.net/t12Ky.png.

If there's a method in JavaScript that can accomplish this functionality, please advise. Otherwise, how can I achieve it?

Answer №1

Adding an index is just as easy as adding an item in the template.

<template slot="rows" slot-scope="{ item: booking, index: index }">
  <tr>
    <td>{{ index }}</td>
    <td></td>
    <td></td>
    <td>{{ fullName(booking.user) }}</td>
    <td>{{ unitName(booking.search_by) }}</td>
    ...
  </tr>
</template>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to update the appearance of each item within an array by utilizing the ForEach() method

I am working on a function that dynamically creates new divs based on a specific condition. Once these divs are created, I store them in an array using the .push() method like so: function SnakeBody(){ BodySnake = document.createElement("div"); tabulei ...

Refreshing dynamically added rows through ajax updates

I'm struggling to clearly articulate my problem. Currently, I have a function that retrieves values from a database using ajax and then dynamically adds each result as a row in a table. This allows users to edit or delete any row as needed. I'm ...

What is the best method to retrieve the value of a {{variable}} from a Django template within a JavaScript environment?

I am currently retrieving the value of img from views.py. I would like it so that when a user clicks on the image, it opens in a modal window. index.html image sections: <!-- Card body --> <div class="card-body"> {% for val in da ...

Having issues with the script not functioning when placed in an HTML document or saved as a .js file

Even though the database insertion is working, my script doesn't seem to be functioning properly. The message "successfully inserted" appears on the saveclient.php page instead of the index.html. In my script (member_script.js), I have placed this in ...

What could be the reason for my post jQuery Ajax request sending JSON data?

After downloading some code, I came across the following fragment: function FetchCommentsBySessionIDWCF_JSON() { varType = "POST"; varUrl = "service/CommentSessionIDWCFService.svc/FetchCommentsByPost"; varData = ' ...

What is a way to retain the value of a variable after a request, while starting off with a different value on the initial load?

In my Flask application, users have the option to choose a specific time period with a start date and an end date. When the page initially loads, I want the start date to default to the first day of the current month and the end date to be the current day. ...

Bringing in manageable RxJS operators

RxJS 5.5 has undergone a significant change and has introduced lettable operators to replace the traditional operators we were using previously. In the article, there is a note that states: Lettable operators can now be imported from rxjs/operators, bu ...

Vue - Utilizing child slots in the render method

Within my component, I am working with a default slot and attempting to enhance the layout by wrapping each item in the slot within a div. However, I am facing an issue where I need to retrieve the classes of one of the slot elements, but the VNode element ...

What can be done to prevent unnecessary API calls during re-rendering in a React application?

On my homepage, I have implemented code like this: {selectedTab===0 && <XList allItemList={some_list/>} {selectedTab===1 && <YList allItemList={some_list2/>} Within XList, the structure is as follows: {props.allItemList.map(ite ...

Attempting to eliminate a div element housed within an iframe by utilizing the onload event

Is there a way to remove specific div tabs from within an iframe by using the onload function set within the iframe itself? I want everything to be in one location for simplicity. It's important to note that I want to utilize the onload WITHIN this &l ...

Is there a way for me to identify what deletes CSS classes from an element during the first page load?

On a page where an element (specifically, a TextBox) initially has two CSS classes assigned when it loads, something strange is happening. After the page renders and JavaScript runs, the class attribute of the input element mysteriously becomes empty. I c ...

convert a string to JSON format using Node.js Express

Currently, I am viewing some string data in a browser that has been processed using python-node js express. The data looks something like this: In order to manipulate the data more effectively, I would like to convert it into JSON format that follows this ...

Creating multidimensional arrays with Javascript or jQuery

Here is an example of an array: var ProG = [[1,0,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]; A hidden field (id=prog-id) in a form is used to send this array to the server: jQuery('#prog-id').val(JSON.stringify(ProG)); ...

Best practices for implementing the <head> tag in an Angular directive

After attempting the solution provided in this post for my Angular app, I ran into some issues. To try and resolve the problem, I decided to introduce a custom tag (<mytag>) into the head section, which allowed me to get the directive working by subs ...

Ways to retrieve the data received from an axios.post request in the server-side code

Currently, I am working on a project that involves using React for the frontend and Spring Boot for the backend. However, I am facing an issue with retrieving data that I have sent using Axios from the frontend to the backend. The code snippet below show ...

Determining the index of an element in an array using PHP

If I have an array like this and I'm iterating through it: $sidebar = array("Best of the Month" => $featuredBestMonth, "Featured Content" => $featuredContent); <? while($item = current($sidebar)):?> <? if($item) ...

I am encountering issues with Axios when bundled with electron - what steps can I take to troubleshoot a compiled exe with electron?

I recently developed a VUE JS application that consumes data from a News API endpoint. To achieve this, I utilized Axios for fetching the data as shown below: import axios from "axios"; let baseURL = `https://newsapi.org/v2`; let apiKey = process ...

Trouble with Bootstrap modal implementation when using ajax and looping through data

I am having an issue with using the BS modal to display a form containing a select box and updating records in the database via an ajax call. The trigger button to open the modal consists of <i></i> tags with the same class name, itagbtn, and d ...

Issue with integrating NW.js child processes in a Vue.js application

I am looking to develop a Vue.js application using Node Webkit (Nw.js). The application needs to execute a binary file, so I attempted the following: const exec = require("child_process").exec; exec( '"C:\\someBin.exe" /someOptions&a ...

Converting JSEncrypt for PHP Asymmetric Encryption

I am attempting to establish Asymmetric encryption between a client and server, where the client possesses the public key and the server holds the private key. On the client side, I am using JSEncrypt in JavaScript to encrypt data with my public key. I th ...