Using VueJs and BootstrapVue, you can easily set up a table to delete items only on the

I have set up a page showcasing all my items in a BootstrapVue b-table. Each item has the option to be deleted. However, I encountered an unexpected issue when I enabled pagination using the b-pagination element and :per-page attribute. The problem arises when navigating to the next pages, as it seems to delete items from the first page instead of the current page.

<b-table
  id="traffic-routes"
  :fields="fieldsForTrafficRoutes"
  :items="itemsForTrafficRoutes"
  :per-page="perPageForTrafficRoutes"
  :current-page="currentPageForTrafficRoutes"
>
    <template v-slot:cell(action)="data">
      <div class="d-flex align-items-center justify-content-end">
        <a class="action-icon mr-2"
          @click="removeRow(data.index)"
        > Delete </a>
     </div>
   </template>  

</b-table>

<b-pagination
  v-model="currentPageForTrafficRoutes"
  aria-controls="traffic-routes"
  align="right"
  :total-rows="
  itemsForTrafficRoutes ? itemsForTrafficRoutes.length : 0"
  :per-page="perPageForTrafficRoutes"
></b-pagination>

export default {
  data() {
    return {
      perPageForTrafficRoutes: 5,
      currentPageForTrafficRoutes: 1,
      // ...
    }
  },
  computed: {
    ...mapGetters([
      'getAllTrafficRoutes',
    ]),
    itemsForTrafficRoutes() {
      return JSON.parse(JSON.stringify(this.getAllTrafficRoutes));
    },
  }
}

To make the items update dynamically for each page, I adjusted the code as follows:

itemsForTrafficRoutes() {
  const foo = JSON.parse(JSON.stringify(this.getAllTrafficRoutes));
  return foo.slice((this.currentPageForTrafficRoutes - 1) *
    this.perPageForTrafficRoutes, this.currentPageForTrafficRoutes * this.perPageForTrafficRoutes
  );
},

This modification is supposed to display unique items for each page, but unfortunately, the table only shows the first page and remains empty on subsequent pages despite the items being present.

Answer №1

That's the reason why the index from the scoped slot is causing confusion. The index corresponds to the rows displayed on the screen, not the actual position of the item in the array assigned to the items prop.

You can find more information about this in the documentation under the notes section for Scoped field slots.

The index might not always match the exact index of the row in the table, as it is calculated after filtering, sorting, and pagination have been applied to the original data. The index will represent the displayed row number. This number will correspond to the indexes from the optional v-model variable.

To address this issue, consider using a unique identifier from your object if available or explore alternative methods to resolve it.

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

Update the `name` attributes of input elements following the retrieval of HTML data from an action using AJAX in an ASP

I am working on a basic ajax request that retrieves a generated HTML from the server. Here is the code snippet: $.ajax({ url: '/GetData' type: "POST", dataType: "html", data: ..., success: function(data) { // In this ...

Is there a way to retrieve random data based on either product id or slug within a single component using useQuery? Currently, all components are displaying the same data

Here is the code I wrote: const fetchCartItem = async () => { if (token) {const {data } = await axios.get(API.GET_PRODUCT_DETAILS_BY_PRODUCT_ID.replace("[ProductID]",item?.ProductID),{headers:{Authorization: token,},});setCartLoading(fal ...

Error: Module not found '!raw-loader!@types/lodash/common/array.d.ts' or its type declarations are missing

I encountered a typescript error while building my NEXT JS application. The error message was: Type error: Cannot find module '!raw-loader!@types/lodash/common/array.d.ts' Below is the content of my tsConfig.json file: { "compilerOptions& ...

Is there a glitch in the console when sorting an array of dates?

I'm puzzled by the fact that the console is displaying a sorted array in both logs. It doesn't make sense to me because it should not be sorted at the first log, right? static reloadAndSortItems() { let array = []; const items = Store. ...

Is there a specific code repository available that can verify and transform blog comments into XHTML strict format?

I'm currently developing a PHP website that allows users to make comments similar to a blog, and I am specifically interested in restricting the use of certain HTML tags. Is there any existing library that can process user comments and output valid XH ...

Vows, Tobi, and Node.js come together for comprehensive REST API testing

Currently, I am in the process of merging the examples here and here to create a vows test for my node.js / express application that does the following: Creates a new user object Verifies that the response is correct Utilizes the returned _id to perform ...

Solve the problem with SCSS at the component level in NextJS

I've decided to transition my regular React app to Next.js. In the past, I would simply import SCSS files using: import from '.componentName.scss' However, now I need to import them using: import style from 'componentName.module.scss ...

Assign the input text field's value programmatically in the code-behind of a C# Asp.net application

I am attempting to change the value of an HTML input field from C# code behind. These inputs are created through a JavaScript loop, so I have not had much success using run at server or assigning values through <%= %>. Below is my script: var mytab ...

Handle changes to input values on ng-click even if they were made outside of Angular's control

Looking to pass input values on ng-click even when they are changed outside of Angular. Everything works fine when manually typing, but once the inputs have dynamic values, ng-click passes empty form data. Below is the HTML code snippet: <form id="form ...

Exploring ways to retrieve nested values from JSON data using the Instagram API and Javascript

Trying to modify the script found at https://github.com/bigflannel/bigflannel-Instafeed in order to access Instagram photos on a website. Unfortunately, the script does not currently support displaying photo comments. I attempted to make modifications that ...

Adjust the field of view of the camera in ThreeJS

I'm currently working on adjusting the field of vision for a camera without having to create a new one. So far, I've successfully achieved this for the position using the following code: camera.position.set() Now, I'd like to implement a s ...

Applying Tailwind styles to dynamically inserted child nodes within a parent div

Currently, I am in the process of transitioning my website stacktips.com from using Bootstrap to Tailwind CSS. While initially, it seemed like a simple task and I was able to replace all the static HTML with tailwind classes successfully. However, now I ha ...

Changing the InnerHTML of a tag in JavaScript using class and id attributes

When it comes to handling these links <div class="post_actions"> <a class="color-transition article_delete" href=""><i class="fa fa-pencil"></i></a> <a class="color-transition article_edit" href="#" id="1">< ...

Modify the size of images retrieved from the Twitch API

I have a request to the Twitch API to retrieve a list of top games and show their box art, but I'm facing an issue where the image will only display if I adjust the width and height values in the provided link. Is there a way to modify these values wi ...

Issue with retrieving query results using node_redis client

I've been struggling with a particular issue that I just can't seem to solve. The problem revolves around not being able to retrieve output values from a Redis query. My setup involves using the node_redis client as the Redis driver for my Node.J ...

Implementing onClick event handling in Material UI components using Typescript

I am attempting to pass a function that returns another function to material UI's onTouchTap event: <IconButton onTouchTap={onObjectClick(object)} style={iconButtonStyle} > <img alt={customer.name} className="object-img" src={obj ...

Can scrollHeight ever be less than clientHeight or offsetHeight?

Is it guaranteed that the output of Math.max(el.scrollHeight, el.offsetHeight, el.clientHeight) will always be equal to el.scrollHeight? Typically, clientHeight <= offsetHeight <= scrollHeight. While there are rare instances where clientHeight > ...

Adding fresh data to a C3.js line graph

I am attempting to dynamically update a C3.js line chart using a function that retrieves a set of x and y values from a database. The function I want to use for inserting the data is: function insertGraph(yAxis, xAxis, Header) { setTimeout(function () ...

What is the most efficient method for importing external geometries into Three.js without causing any interference with the user interface?

At this moment, I am facing an issue with loading multiple .obj files (totaling 20MB) into Three.js. Although everything works fine once the files are loaded, the main problem lies in the fact that it takes approximately 25 seconds for Three.js to proces ...

Enhance your security with Ember-simple-auth when using ember-cli-simple-auth-token

Currently, I am in the process of utilizing ember-simple-auth alongside ember-cli-simple-auth-token: "ember-cli-simple-auth-token": "^0.7.3", "ember-simple-auth": "1.0.1" Below are my configurations: ENV['simple-auth-token'] = { authoriz ...