Pie*_*luc 10 jquery addclass datatables
如何在我在数据表中添加的行中添加一个类?
如果不可能,我该如何使用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";
}
});
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我一个错误.
这是我添加行的方式:
oTable.fnAddData(arr);
Run Code Online (Sandbox Code Playgroud)
Joh*_*ika 19
尝试将您更改fnRowCallback为以下内容:
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
nRow.className = "gradeX odd";
return nRow;
}
Run Code Online (Sandbox Code Playgroud)
您可以参考官方文档以进一步了解此回调函数.
小智 9
您可以按照文档中的说明在数据中添加类名.
http://www.datatables.net/examples/server_side/ids.html
使用DT_RowId用于添加ID为任何行
使用DT_RowClass用于添加类的任何行
使用DT_RowData用于添加HTML5数据对象的任何行
例如:
"data":[{
"DT_RowId":"row_5",
"first_name":"Airi",
"last_name":"Satou",
"position":"Accountant",
"office":"Tokyo",
"start_date": "08年11月28日",
"工资":"162,700美元"
}]
jas*_*nac -4
好吧,也许我不明白你的问题是什么,但如果你只是添加行,为什么不在添加之前设置类呢?像这样,有点草率,例子:
jQuery("<tr />")
.html(your_var_containing_the_interior_dom)
.addClass("yourClass")
.appendTo(jQuery("#yourTable"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31319 次 |
| 最近记录: |