简体   繁体   中英

Tabulator.js: get/select rows on current page

I am using an amazing tabulator plugin for managing tabular data, API is very clear and reliable but i cant do a very simple thing: get/select all rows on current page.

Custom row selection can look like this:

table.selectRow(table.getRows().filter(row => <<Custom Selection>>);

Where Custom selection has to respect the current page, but i dont get from where i can take it.

Maybe i am missing something?

There is no way to do that directly form Tabulator, but is should be fairly easy to do yourself with a bit of JavaScript.

First you want to get the rows that are visible on that page:

var pageRows = table.getRows(true);

Then you want to get the selected rows

var selectedRows = table.getSelectedRows();

then you want to find rows that exist in both arrays, these will be the selected rows on that page:

var rows = selectedRows.filter(value => -1 !== pageRows.indexOf(value));

Assuming the column name of your index is 'id' you can do the following:

var selectedData = table.getSelectedData();
jQuery.map(selectedData, function(value, index) {
    console.log(value.id);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM