简体   繁体   English

如何在不使用TableTool的情况下从jquery数据表中获取选定的行索引

[英]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.

相关问题 jQuery Datatables-如何在单击该行中的按钮时获取该行的索引 - jQuery Datatables - How to get the index of a row when a button in that row is clicked jQuery DataTables:如何通过tr的行id获取行索引(或nNode)? - jQuery DataTables: How to get row index (or nNode) by row id of tr? 如何获取数据表中的行索引? - How to get row index in Datatables? 如何从数据表中的复选框选定行中获取数据 - How to Get Data from checkbox selected row in dataTables JQuery DataTables使用分页时如何从表中获取选定的行? - JQuery DataTables How to get selected rows from table when we using paging? 如何从jquery数据表中的选定数组中获取值? - How to get value from selected array in jquery datatables? 如何通过使用jQuery从WebGrid的选定行中获取值 - How to get the value from a selected row of a webgrid by using jquery jQuery数据表:选择扩展:如何在init上选择第一行以及如何至少选择一行 - jquery datatables: Select Extension: How to select first row on init and how to get at least one row selected 从DataTables API获取当前行索引 - Get current row index from DataTables API 在不使用jquery的情况下单击获取引导表的行索引 - Get the row index of bootstrap table in click without using jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM