[英]How to get selected row index from jquery datatables without using TableTool
I need to get the row id or index of user selected rows from jquery datatables without using the TableTool. 我需要不使用TableTool从jquery数据表中获取用户选择的行的行ID或索引。 Once I get the indexes or the Ids, I will use them to select these rows after the user comes back to the same page. 一旦获得索引或ID,在用户返回同一页面后,我将使用它们来选择这些行。 How do I get the row Id or index of the select rows? 如何获取行ID或选择行的索引? Many thanks ! 非常感谢 !
JSP code: JSP代码:
// when a row is selected, I want to get the row id or index
$('#userTable tbody tr').on('click', function()
{
var oTable = $('#userTable').dataTable();
var data = oTable.fnGetData(this);
selectedRowId = data[4];
alert(selectedRowId); // this printed "undefined"
var rowIndex = oTable.row(this).index();
alert(rowIndex); // this alert didn't even get invoked.
});
var rowIndex = oTable.row(this).index();
The above will work but you have to use: 上面的方法可以工作,但是您必须使用:
var oTable = $('#userTable').DataTable();
which will return the API and should allow you to use row(this).index()
这将返回API,并应允许您使用row(this).index()
Instead Of: 代替:
var oTable = $('#userTable').dataTable();
However without seeing a working copy of the code (JSFiddle maybe) I am unsure why the fnGetData()
is not working. 但是,没有看到代码的有效副本(也许是JSFiddle),我不确定为什么fnGetData()
无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.