且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在TR和TD中添加属性?

更新时间:2023-11-24 21:53:28

使用 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.