如何在TR和TD中添加属性? [英] How to add attribute in TR and TD?
本文介绍了如何在TR和TD中添加属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用数据数据表添加行,我可以这样做
I want to add row using data datatables, and I can do it like this
var table = $('#mytable').DataTable();
table.add.row(['first column', 'second column', 'three column', 'etc']);
我需要的是这样的东西(TR和TD标签中的某些属性)
What I need is something like this (some attribute in TR and TD tag)
<tr id="someID">
<td>first column</td>
<td>second column</td>
<td>three column</td>
<td id="otherID">etc</td>
</tr>
如何使用数据表?
推荐答案
使用 createdRow
和 columns.createdCell
选项以定义在创建 TR
和 TD
元素时将调用的回调函数。
Use createdRow
and columns.createdCell
options to define a callback function that will be called when TR
and TD
element are created.
$('#example').dataTable( {
'createdRow': function( row, data, dataIndex ) {
$(row).attr('id', 'someID');
},
'columnDefs': [
{
'targets': 3,
'createdCell': function (td, cellData, rowData, row, col) {
$(td).attr('id', 'otherID');
}
}
]
});
请参见此示例进行代码和演示。
See this example for code and demonstration.
这篇关于如何在TR和TD中添加属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文