如何将类添加到 jquery 数据表中的新行?
如何将类添加到我在数据表中添加的行?
如果不可能,如何使用 fnRowCallback
或 fnDrawCallback
来更改类?
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);
How can I add a class to the row I'm adding in the datatable?
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";
}
});
The above code is giving me an error.
this is how I add the row:
oTable.fnAddData(arr);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(8)
七婞2024-09-15 19:38:43
您可以按照文档中的说明在数据本身中添加类名。
http://www.datatables.net/examples/server_side/ids.html
使用 DT_RowId 为任意行添加 ID
使用 DT_RowClass 为任何行添加类
使用DT_RowData将html5数据对象添加到任何行,
例如:
“data”:[
{
“DT_RowId”:“row_5”,
"first_name": "艾里",
"last_name": "佐藤",
"position": "会计师",
“办公室”:“东京”,
"start_date": "2008 年 11 月 28 日",
"工资": "$162,700"
}]
心房的律动2024-09-15 19:38:43
试试这个:
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var id = aData[0];
$(nRow).attr("id",id);
if ( jQuery.inArray(aData[0], gaiSelected) != -1 )
{
$(nRow).addClass('row_selected');
}
return nRow;
}
要将行添加到数据表,请尝试以下代码:
http://datatables.net/examples/ api/add_row.html
/* Global var for counter */
var giCount = 1;
$(document).ready(function() {
$('#example').dataTable();
} );
function fnClickAddRow() {
$('#example').dataTable().fnAddData( [
giCount+".1",
giCount+".2",
giCount+".3",
giCount+".4" ] );
giCount++;
}
十雾2024-09-15 19:38:43
官方文档说:
var table = $('#example').DataTable();
table
.rows.add( [
new Pupil( 43 ),
new Pupil( 67 ),
new Pupil( 102 )
] )
.draw()
.nodes()
.to$()
.addClass( 'new' );
请阅读:rows.add()
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
尝试将您的
fnRowCallback
更改为以下内容:您可以参考官方文档< /a> 进一步了解这个回调函数。
Try changing your
fnRowCallback
to the following:You can refer to the offical documentation to further understanding this callback function.