c# - JQuery Datatables 在所有可用页面上获取所有“选中”复选框
问题描述
希望你能帮我找到解决我遇到的这个问题的方法。重点是我有一个视图——带有数据表的 C# 和 JQuery——它绘制了一个包含数千行的数据表。数据表是分页的,它的第一列有一个复选框 dom 对象,用户可以检查所有这些对象,一个或特定的。当用户提交页面时,我只得到了用户访问的最后一页的选中项,而我需要的是数据表中所有可用页面的所有选中行。任何人都知道如何编写返回该代码的代码?
我已经拥有的代码是这个(只返回最后一页检查的行):
var rows_selected = $('input[type="checkbox"]:checked')
var index = 0;
rows_selected.each(function () {
console.log('ListadoActores[' + index + ']'),
$('<input>', {
type: 'hidden',
value: $(this).attr('id').replace('chk', ''),
id: $(this).attr('id').replace('chk', ''),
name: 'ListadoActores[' + index + ']',
}).appendTo('#GenFileForm');
index = index + 1;
});
$("#GenFileForm").submit();
希望你能帮我解决这个问题。提前致谢。
解决方案
正如@freedomn-m 所说,您需要访问 Datatables API 才能获取所有数据。
在提交时,放置一些如下代码:
var table = $('#example').DataTable();
var rows = [];
table.rows().every( function () {
var d = this.data(); //this will get the data for the row.
rows.push(d);
} );
//You can then POST the rows and work with them
推荐阅读
- clang - 如何以 clang 格式使用 --dry-run 选项?
- html - 试图阅读 HTML 以从我的经纪人那里找到 XRP 的价格
- python - 按下按钮后,使用 Flask 打印 HTML 中的文本框文本
- java - 就地删除某些字符
- flutter - 在 Mutation Widget (Graphql) 上调用了 getter 'value' 为 null !谁能帮我?
- json - 无法用字符串“foo”索引字符串
- python - 同一台PC机同时运行两个django项目的认证登录问题
- python - 如何在 Python 中的单元格上呈现带有工具提示的表格?
- ios - TextView边框颜色不变
- python - 如何在pandas df中选择值也出现在过滤列中的行?