buttons().disable()
自:Buttons 1.0.0 起
禁用选定的按钮。
请注意 - 该属性需要 DataTables 的 Buttons 扩展。
描述
根据某些外部逻辑启用和禁用按钮通常非常有用。一个常见的示例是编辑按钮,当表中没有选中任何行时该按钮被禁用。
当按钮被禁用时,其视觉外观会更新以显示其非活动状态(通过将类 disabled
添加到按钮元素来完成此操作)。此外,当单击禁用按钮(或通过键盘或 button().trigger()
激活它)时,不会执行按钮的操作。
可以使用此方法动态禁用按钮。与其对应的方法 buttons().enable()
不同,此方法不能用于同时启用和禁用按钮,它只能用于禁用。
类型
示例
禁用所有按钮
123var
table =
new
DataTable(
'#myTable'
);
table.buttons().disable();
在逻辑条件下设置启用状态
123456789var
table =
new
DataTable(
'#myTable'
);
var
buttons = table.buttons([
'.edit'
,
'.delete'
]);
if
(table.rows({ selected:
true
}).indexes().length === 0) {
buttons.disable();
}
else
{
buttons.enable();
}
Post new comment
Contributions in the form of tips, code snippets and suggestions for the above material are very welcome. To post a comment, please use the form below. Text is formatted by Markdown.
To post comments, please sign in to your DataTables account, or register:
Any questions posted here will be deleted without being published.
Please post questions in the Forums. Comments are moderated.