datatables 添加title屬性


使用 createdRowcolumns.createdCell options 來定義一個回調函數用於創建 TR and TD 元素時添加屬性.

$('#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');
      }
    }
  ]
});

Example:給td元素添加title屬性

columns: [{
    "sClass": "member",
    "data": "id",
    "render": function (data, type, full, meta) {
      return '<i class="check_icon check_false" data-value="' + data + '">';
    },
    "bSortable": false
  },
  {
    "data": "name",
    'createdCell':  function (td, cellData, rowData, row, col) {
      $(td).attr('title', cellData); 
    }
  },
  {
    "data": "email",
    'createdCell':  function (td, cellData, rowData, row, col) {
      $(td).attr('title', cellData); 
    }
  }
}]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM