我正在使用带有自定义按钮的数据表。我正在寻找examples,也用谷歌搜索了一下,但我没有找到可行的解决方案。
问题是,当我取消选择该行时,按钮仍然处于启用状态。选择/取消选择行时启用/禁用按钮的正确方法是什么?
var table = $('#example').DataTable( {
serverSide: true,
dom: 'Bfrtip',
ajax: '/get?op=2',
columns: [
{ data: 'id' },
// more columns
],
buttons: [
{
text: 'New',
action: function ( e, dt, node, config ) {
window.location.href = '/property?option=new'
}
},
{
text: 'Modify',
action: function ( e, dt, node, config ) {
window.location.href = '/property?option=modify&id=' + data.id
},
enabled: false
},
{
text: 'Delete',
action: function ( e, dt, node, config ) {
},
enabled: false
}
],
select: true
} );
table.on( 'select', function () {
var selectedRows = table.rows( { selected: true } ).count();
table.button( 1 ).enable( selectedRows === 1 );
table.button( 2 ).enable( selectedRows === 1 );
table.button( 3 ).enable( selectedRows === 1 );
//table.button( 1 ).enable( selectedRows > 0 );
} );
另外,如何获取所选行的 id 值?
action: function ( e, dt, node, config ) {
window.location.href = '/property?option=modify&id=' + data.id
},