黃聰:Jquery+DataTables插件,如何在ajax調用服務器數據後,自動給tr添加id屬性
阿新 • • 發佈:2017-10-07
jquer ida ted fnr pos sid idt 事件 all
http://legacy.datatables.net/usage/callbacks#fnRowCallback
主要通過 fnCreatedRow 事件來實現
var table = $(‘#table_id‘).dataTable( { "processing": true, "serverSide": true, "ajax": { "url": "#", "type": "POST", "data" : { "action" : "table-ajax-data" } },"columns": [ { "data": ‘id‘, "name": ‘編號‘, "width": ‘80px‘ }, { "data": ‘cat‘, "name": ‘分類‘ }, { "data": ‘sub_cat‘, "name": ‘子類‘, "orderable": false, "visible": false, "searchable": false } ], "fnCreatedRow": function( nRow, aData, iDataIndex ) { if( typeof( aData.id ) != "undefined" ) { $( nRow ).attr( "tr_id", aData.id ); } } } );
黃聰:Jquery+DataTables插件,如何在ajax調用服務器數據後,自動給tr添加id屬性