简体   繁体   English

Tabulator.js:获取/选择当前页面上的行

[英]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.我正在使用一个惊人的表格插件来管理表格数据,API 非常清晰可靠,但我不能做一件非常简单的事情:获取/选择当前页面上的所有行。

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.没有办法直接从 Tabulator 中做到这一点,但是使用一些 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:假设您的索引的列名是“id”,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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