使jQuery数据表保持搜索/排序时分配的行号 [英] Make jQuery datatables keep the row number assigned when searching/sorting
本文介绍了使jQuery数据表保持搜索/排序时分配的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码在jQuery Datatables中创建行号:
I've got the following code to create a row number in jQuery Datatables:
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull){
var index = iDisplayIndexFull + 1;
$('td:eq(0)', nRow).html(index);
return nRow;
},
但是,当我搜索某个值时,行号更新。这是预期的。我的问题是,有没有在最初创建行数后保持不变?
However, when I search for a certain value, the row numbers update. This is expected. My question is, is there anyway to make the row numbers remain the same after they are initially created?
示例:
Initial output
1 Team1
2 Team2
3 Team3
4 Team4
5 Team5
After Searching
2 Team2
5 Team5
这可能吗? / p>
Is this possible?
推荐答案
"fnDrawCallback": function ( oSettings ) {
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
{
$('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
}
}
}
这篇关于使jQuery数据表保持搜索/排序时分配的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文