简体   繁体   English

数据表所选行的数量

[英]Datatables number of selected rows

I am using Datatables with selected extension with checkboxes and I am trying to get the number of the selected rows after I deselect one or all. 我使用带有复选框的 选定扩展名的数据表,我试图在取消选择一个或全部后获取所选行的数量。

This code works perfectly with all deselection (I got always zero) but If I deselect only one row I get the number of selected rows plus one. 这段代码完全适用于所有取消选择(我总是为零)但是如果我只取消选择一行,我会得到所选行的数量加一。 It seems the event fire earlier somehow. 似乎事件以某种方式提前开火。

table.on('deselect', function(e, dt, type, indexes) {

  var numberOfSelectedRows = table.column(0).checkboxes.selected().length;

  // ...

});

If I wrap the code with a setTimeout It works perfectly, but it's messy. 如果我用setTimeout包装代码它完美地工作,但它很麻烦。

Can't you just use rows_selected.length if you're following the jsfiddle provided by the checkboxes lab? 如果你正在关注复选框实验室提供的jsfiddle,你不能只使用rows_selected.length吗? So on click of the row/checkbox, just check the array length to see what the count is for what is still checked... 因此,单击行/复选框,只需检查数组长度,以查看仍在检查的内容的计数...

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

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