如何将类添加到 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)
尝试将您的
fnRowCallback
更改为以下内容:您可以参考官方文档< /a> 进一步了解这个回调函数。
Try changing your
fnRowCallback
to the following:You can refer to the offical documentation to further understanding this callback function.
您可以按照文档中的说明在数据本身中添加类名。
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"
}]
You can add the classname in your data itself as described in the documentation.
http://www.datatables.net/examples/server_side/ids.html
use DT_RowId for adding id for any row
use DT_RowClass for adding class for any row
use DT_RowData for adding html5 data object to any row
eg:
"data": [
{
"DT_RowId": "row_5",
"first_name": "Airi",
"last_name": "Satou",
"position": "Accountant",
"office": "Tokyo",
"start_date": "28th Nov 08",
"salary": "$162,700"
}]
试试这个:
要将行添加到数据表,请尝试以下代码:
http://datatables.net/examples/ api/add_row.html
Try this:
For adding row to datatable try this code from :
http://datatables.net/examples/api/add_row.html
官方文档说:
请阅读:rows.add()
Official documentation says:
Please read: rows.add()
这应该可以解决问题:
This should do the trick:
阅读文档后,这对我有用:
After reading the documentation this work for me:
好吧,也许我不明白你的问题是什么,但如果你只是添加行,为什么不在添加之前设置类呢?像这样,有点草率,例子:
Alright, perhaps I'm not understanding exactly what your question is, but if you were just adding the row, why not set the class before you add it? Like this, somewhat sloppy, example: