如何在jquery数据表中的新行添加一个类? [英] How to add a class to a new row in a jquery datatables?
本文介绍了如何在jquery数据表中的新行添加一个类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在datatable中添加一行?
How can I add a class to the row I'm adding in the datatable?
如果不可能,如何使用 fnRowCallback
或 fnDrawCallback
更改课程?
If not possible, how can I use fnRowCallback
or fnDrawCallback
to change the class?
oTable = $('#example').dataTable( {
"bJQueryUI": true,
"bSortClasses": false,
"sDom":'T<"clear">',
"sPaginationType": "full_numbers",
"sDom": 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
var oSettings = oTable.fnSettings();
oSettings.aoData[iDisplayIndex].nTr.className = "gradeX odd";
}
});
上面的代码给我一个错误。
这是我添加的行:
oTable.fnAddData(arr);
推荐答案
尝试更改您的 fnRowCallback
到以下内容:
Try changing your fnRowCallback
to the following:
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
nRow.className = "gradeX odd";
return nRow;
}
您可以参考正式文档以进一步了解此回调函数。
You can refer to the offical documentation to further understanding this callback function.
这篇关于如何在jquery数据表中的新行添加一个类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文