jquery - 如何选择数据表 1.9 中当前页面中显示的行?
问题描述
我正在使用 datatable 1.9 和 tabletool.js 2.1.5。我总共有 23 条记录,每页 10 条记录。我想选择当前显示的页面记录。
我使用了 TableTools.js 按钮 (select_all)。但这会选择数据表的所有行。我试过了
$('#file-records> tbody > tr').each(function() {
TableTools.fnGetInstance('file-records').fnSelect($(this));
});
上面的代码给了我一个错误 Uncaught TypeError: Cannot read property 'nTr' of undefined
解决方案
我已经实现了以下
$('#file-records> tbody > tr').each(function() {
$(this).addClass("active");
});
$(this).addClass("active"); 添加我在 css 文件中编写的背景颜色:#017ebc。
所以当你想获得选定的行值时,你可以拥有
$('#file-records> tbody > tr').each(function() {
if($(this).hasClass('active')){
console.log($(this)[0]);
}
});
$(this)[0] 是我的行属性,我们可以从中获取实际的行内容
推荐阅读
- r - 在 R arcgisbinding 中定义字段类型
- scala - 在 Chisel 中实现 Verilog $onehot 任务
- php - 搜索大量字符串php和mysql
- swift - IOS如何取自定义可调整大小的SKVideoNode来引用自定义可调整大小的ARImageAnchor SCNPlane的位置和大小
- angular - url 中的“%2b”不适用于 url 重写
- python - 是否可以在 str.format() 中使用循环?
- java - Perl 的 require 命令的 java 等效项是什么?
- lua - 仅在第一个完成后才开始第二个 while 循环
- excel - 可以在运行时自行编辑的VBA MACRO?
- ios - Xcode 中的 libcommonCrypto.dylib 在哪里?