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

Discover the HTML of a different website using Javascript

I'm currently developing a basic webcrawler that will display all the links found on a specified website. Here's what I envision my program doing: - enter a URL: http://www.example.com/ - the program retrieves the HTML source and locates all th ...

Concealing overflow in a sticky container when a fixed child element is present

I am currently working on a website where I have implemented slide-up section panels using position: sticky while scrolling. However, I am encountering issues with fixed elements within the sticky panels not properly hiding outside of the respective sectio ...

Utilizing HTML5 to automatically refresh the page upon a change in geolocation

I have a web application built with AngularJS. One of the functionalities is activated only when the user is in close proximity to specific locations. To make this work, I can constantly refresh the page every 5 seconds and carry out calculations to dete ...

Laravel Sanctum - Access Denied post login

My current project is a small web app developed using Laravel 8 sanctum and Vue. I have set up everything on both my local environment and the production server using Docker, ensuring consistency. The application is running smoothly on a subdomain called s ...

The Google Charts chartRangeFilter displays incorrectly upon reducing the height to a specific, seemingly random level

I am relatively new to web coding and currently working on a dashboard project for my client. I am using Google Charts to display the water level data that I collect. My issue is with the chartRangeFilter control - it works fine when the height is large en ...

Properly setting up event handling for a file input and Material UI Button

In my attempt to create a customized form using material UI elements, I am facing an issue. The form allows users to upload files and add notes for each option, which are stored in an array in the component's state. Here is a simplified version of th ...

Guide on exporting type definitions and utilizing them with npm link for a local package

I am in the process of developing a new testing tool called tepper as an alternative to supertest. My goal is to make this package available in both ESM and CJS formats. However, I'm encountering an issue where users of the library are unable to locat ...

Can AngularJS Filters be used to convert a number into a string, but not the other way around?

After researching Angular JS filters, I discovered that the number filter is used to format a number as a string. However, there doesn't seem to be a built-in filter for converting a string to a number. In an attempt to solve this issue, here is so ...

I am interested in monitoring for any alterations to the @input Object

I've been attempting to detect any changes on the 'draft' Object within the parent component, however ngOnChange() does not seem to be triggering. I have included my code below, but it doesn't even reach the debugger: @Input() draft: ...

Tips for displaying the message "{"POWER":"ON"}" within the else if statement (this.responseText == ({"POWER":"ON"})) {

Hey everyone, I'm trying to adjust the color of a button on my webpage based on the response I receive from this.responseText. I understand the JSON response, but for some reason, I can't seem to incorporate it into my code. If anyone could lend ...

React input value doesn't get updated on onChange event causing the input

Currently, I'm working on a React application that requires a table with inputs in each row. To achieve this, I am utilizing Material-UI and Formik. However, I've encountered a bug where input fields lose focus whenever I type something into them ...

The execution of the return statement in the catch block is unsuccessful

Here is a simple example that results in an error because the variable tl was not specified: function allmatches() { SpreadsheetApp.getActive().getSheetByName('data').getRange('A1').setValue(tl) } To track any errors that occur durin ...

Issue with Refreshing onRowAdd in React Material Table

I am currently using Material Table to display my table data. However, when I use the onRowAdd function to add a new row, the page does not refresh properly. Instead, it reloads and gets stuck, requiring me to manually refresh again. newData => ...

Changing alert variant dynamically with Vue.js and Bootstrap-Vue

As I work on a vue.js project using bootstrap-vue, I came across the following method to display an alert based on the documentation: <b-alert variant="success" show>Success Alert</b-alert> However, my attempt to achieve this is as follows: ...

The onClick event is not functioning properly with React's select and option elements

Looking for a way to get the option value from each region? const region = ['Africa','America','Asia','Europe','Oceania']; <div className="options"> <select> ...

What are the reasons for a jQuery function to run in a selective manner?

There seems to be some inconsistency in the behavior of this incomplete script that I'm trying to debug. The issue arises when I click off an item, as sometimes the $(editObj).removeAttr('style'); line of code executes and other times it doe ...

Prevent users from editing Dropdown List in Bootstrap Vue

I'm currently working on a project using "Bootstrap Vue" where I have implemented a feature that changes the input fields to readonly mode when the user clicks on the "confirm" button. This functionality is achieved through a boolean variable assigned ...

Ensuring proper execution of the next callback function in an Express get request

I am currently running an express server on nodejs with a specific file structure that I need to convert into a list of links. Included below are my recursive functions for dealing with the file structure. Here are the file structure functions: function ...

Shut down the angular modal

I am currently learning AngularJS and I find myself working on an application that utilizes both angular modal and jqGrid. (I understand this may not be the ideal setup, but for now, I have to make it work with both.) The content of my modal is loaded usi ...

Issue with Jade not displaying external JSON data

I am struggling with a jade template that is supposed to display all possible solutions from the QPX Express search request: { kind: 'qpxExpress#tripsSearch', trips: { kind: 'qpxexpress#tripOptions', requestId: 'RwDOf6H ...