[英]How to get row index in Datatables?
I used following javascript to get row index. 我用下面的JavaScript来获取行索引。 By using this the ID(table header) always starts with 1 in case next 10 values are selected in every page.i need to show next 10 as 11 to 20. Thank you very much..
如果在每个页面中选择了下10个值,则ID(表标头)始终使用1开头。我需要将下10个值显示为11到20。非常感谢。
$(document).ready(function() {
$('#example').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "scripts/server_processing.php",
"aoColumns": [
{
"sTitle": "ID"},
{
"sTitle": "E Mail"},
{
"sTitle": "FirstName"},
{
"sTitle": "LastName"},
{
"sTitle": "Company"},
{
"sTitle": "Course"},
{
"sTitle": "Module"},
{
"sTitle": "Completions"},
{
"sTitle": "First"},
{
"sTitle": "Last",
"sClass": "center"},
{
"sTitle": "Lowest"},
{
"sTitle": "Highest",
"sClass": "center"},
// {
// "sTitle": "#"},
],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var index = iDisplayIndex +1;
$('td:eq(1)',nRow).html(index);
return nRow;
}
});
});
EDIT: 编辑:
Check out this link Datatables-addrow and code is here: 查看此链接Datatables-addrow ,代码在这里:
var t = $('#example').DataTable( {
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": 0
} ],
"order": [[ 1, 'asc' ]]
} );
t.on( 'order.dt search.dt', function () {
t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw();
For getting index in jquery : 为了在jquery中获取索引:
$('#example tbody').on( 'click', 'tr', function () {
alert( 'Row index: '+table.row( this ).index() );
} );
For more information visit Datatables 有关更多信息,请访问数据表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.