且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将行号列添加到jquery数据表

更新时间:2023-11-03 16:37:28

您只需在aoColumns中定义一个空列。



然后在fnRowCallback函数中,您只需编辑您喜欢的列。每次创建新行时,都会运行此回调。



如果您的第一列具有行号,您可以在fnRowCallback中执行此操作:

  var index = iDisplayIndex +1; 
$('td:eq(0)',nRow).html(index);
return nRow;


I want jQuery datatables to automatically create row number column in the first column like datagrid in VB.

It looks like this:

Anyone knows how to do this?

You just define an empty column in aoColumns.

Then in fnRowCallback function you just edit the column how you like. This callback is run every time new row is created.

Basicly if your first column has the row number, you could just do this in fnRowCallback:

var index = iDisplayIndex +1;
$('td:eq(0)',nRow).html(index);
return nRow;