pagination functionality incorporated into element ui tables

Issue with Element UI: when a checkbox is selected and the page is changed, the selected rows' checkboxes are removed. I need to retain the selection items while paging so that users can select items from multiple pages without losing the selections from previous pages.


        <el-table
        ref="multipleTable"
      row-key="id"
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      style="width: 100%;"
    @select="myselect"
    @sort-change="sortChange"
      @selection-change="handleSelectionChange"
    :tree-props="{children: 'children'}"
    >

.......

      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />


and these functions
      myselect(selection, row) {
        console.log('this is selection', selection);
        console.log('this is row', row)
      },

  handleSelectionChange(val) {
    this.selectedShipments = val;
    window.localStorage.setItem('storedShipments', JSON.stringify(this.selectedShipments));
      },

    async getList() {
     this.listLoading = true;
     const { data } = await fetchShipmentList(this.listQuery);
      this.list = data.data;
      this.total = data.total;
      // Just to simulate the time of the request
     this.listLoading = false;
    },

   listQuery: {
        page: 1,
        limit: 10,
        search: undefined,
        status: undefined,
        sort: 'id',
        sortDir:'desc',
      },

Answer №1

Utilize the reserve-selection feature to determine whether to maintain selection after data refreshing, specifically when the type is set to 'selection'. Keep in mind that a row-key is necessary for this functionality.

<el-table
  v-loading="listLoading"
  :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
  element-loading-text="Loading"
  border
  fit
  highlight-current-row
  @selection-change="handleSelectionChange"
  :row-key="getRowKey"
>
  <el-table-column type="selection" width="40" :reserve-selection="true" />

getRowKey(row){
  return row.id
},

Answer №2

Check out this link for more information on tables.

Make sure to utilize the toggleRowSelection function on your table for each item that is selected in your selectedShipments array.

This is how it should be implemented:

    async loadData() {
     this.loading = true;
     const { result } = await fetchTableData(this.query);
      this.data = result.items;
      this.total = result.totalCount;
      // Adding a delay to simulate request time
     this.loading = false;
     // Ensure selection after data update
     this.$nextTick(()=>{
  this.selectedItems.forEach(item=>this.$refs.table.toggleRowSelection(item, true))
     })
    },

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

AngularJS: Utilizing ellipsis for text overflow and optimization

As a beginner in angularJS, I might have made some mistakes... Can anyone guide me on how to properly implement this plugin: https://github.com/BeSite/jQuery.dotdotdot on my table? Currently, the performance of my edit form and table is very slow. What c ...

Troubleshooting problem with printing iframes on Firefox

When attempting to print an iframe with a large amount of data using the code below, I'm encountering an issue in Firefox where only the first page is printed. The rest of the pages are not being included in the printout. window.frames[frameID]. ...

Top scenario and illustration of utilizing clusters in nodejs

I've been exploring the concept of clusters and I'm still a bit unclear about the most effective use-case scenario for them. Can anyone provide an example to help clarify this for me? ...

The element type 'HTMLElement' does not contain a property named 'pseudoStyle'

Currently experimenting with adjusting the height of a pseudo element using Typescript. An error is popping up in my IDE (vscode) as I go along. This is the code snippet I am working with. // choose element let el: HTMLElement = document.getElementById( ...

Directive fails to trigger following modification of textarea model

There is a block of text containing newline separators and URLs: In the first row\n you can Find me at http://www.example.com and also\n at http://stackoverflow.com. The goal is to update the values in ng-repeat after clicking the copy button. ...

Utilizing bcrypt in an axios request

Currently, I am working on an axios call to a specific json file. My goal is to obtain input from a front-end framework and then pass that data to my server using express. The task at hand involves encrypting the password retrieved from request.body.passw ...

Mastering file handling with jQuery File Upload Middleware in Node.js Express: blending files and branding with watermarks

I was successful in setting up the jquery-file-upload-middleware with express.js 4.0, but I am struggling with configuring it properly. Here is the script I used for upload: var upload = require('jquery-file-upload-middleware'); upload.configur ...

Should I use React with Spring Boot or just Spring Boot for this project?

My partner and I are collaborating on a project for our current semester course. As we delve into our research on potential technologies to use, it seems like Spring Boot for the server side along with MySQL or Postgres for the database are emerging as s ...

Creating a dynamic drag-and-drop layout in React using react-grid-layout

Utilizing the react-grid-layout package for implementing drag-drop and resize components, I have successfully achieved the functionality outlined in the documentation. Description of My Issue My challenge lies in creating a dynamic UI where the layout is ...

Fetching JSON data using Javascript/JQuery

My goal is to access JSON data from an online web service that queries a MySQL database for a specific string and use Javascript to present it on an HTML page. My challenge lies in effectively displaying the retrieved information. The relevant part of my ...

The AJAX request was successful, however, the PHP script did not return any

When using an Ajax success function to alert data in JavaScript, there may be occasions where the PHP side shows that the GET array is empty. <script type="text/javascript"> var myArray={ name:"amr", age:22 } myArray =JSON.stringify(myA ...

Custom pagination for next/previous links in Django REST framework

When it comes to backend operations, I have integrated the PageNumberPagination as the DEFAULT_PAGINATION_CLASS. Since I am utilizing vue.js along with fetch, there is no need for me to include the entire URL structure provided by django-rest-framework: " ...

Synchronous: Establishing a connection to MongoDB once the server has successfully launched

I am curious to understand the interaction between Node.js asynchronous functions and MongoDB. If the server initializes before establishing a connection, and if my templates or Ajax requests rely on database data, will the serving of the HTML fail or will ...

Displaying the API request using the UseEffect API is not working upon the page

Sorry if this question has been asked before, but I’m really stuck on this small bug. I’m trying to display a collection of tweets from Firestore when the page loads, but currently it only works after a post request. Here’s my code: useEffect(() ...

Assigning properties in html

When the status is equal to "complete", I need to disable an input tag based on a certain condition. One way to achieve this using javascript is by utilizing the setAttribute method. var element = document.querySelector("input"); element.setAttribute("d ...

Effortless pagination across various pages, utilizing diverse CSS selectors

I've integrated simple pagination into my website, but I've encountered a issue. My navigation consists of CSS tabs, each holding a unique pagination component. Here is the jQuery pagination code snippet: $(function(){ var perPage = 8; var open ...

When trying to convert a function component to a class component, using `npm init react-app` may result in the error `ReferenceError: React is not defined no-undef`

After running npm init react-app appname, I noticed that the file App.js was created, containing a function component: function App() { return ( <SomeJSX /> ); } I decided to change this function component into a class component like this: c ...

The accuracy of real-time visitor numbers in Google Analytics is often unreliable

My website uses Google Analytics to track the page chat.php. The code snippet is correctly placed on the page according to the documentation. Within this page, there is a Flash object that connects users to an IRC chat room. Currently, there are 50 unique ...

Tips for avoiding automatic updates to .js scripts after pressing F5

Is there a method to stop a JavaScript script from resetting when the user refreshes the page? For instance, if I have a picture slider that is constantly changing images, I would like the script to continue where it left off instead of starting over wit ...

Retrieving JSON data from an Axios request in VueJS

I set up a simulated server in Postman to fetch some test data for my Vue application. This is the response I am receiving from the server: I am struggling to access the data information. Here is the code snippet that I am using: <template> <d ...