{hero}

buttons().enable()

版本:Buttons 1.0.0

啟用 / 停用選取的按鈕。
請注意 - 這個屬性需要 DataTables 的 Buttons 擴充套件。

說明

基於某些外部邏輯啟用和停用按鈕通常很有用。 一個常見的例子是當表格中未選擇任何行時,編輯按鈕會停用。

當按鈕被停用時,它的視覺外觀會更新以顯示其停用狀態(這是透過將類別 disabled 新增到按鈕元素來完成的)。此外,當點擊已停用的按鈕(或透過鍵盤或 button().trigger() 以其他方式啟動時),按鈕的動作不會執行。

此方法可用於動態變更選定按鈕的啟用狀態。

類型

function buttons().enable( [ state ] )

說明

設定選定按鈕的啟用狀態。

參數
回傳

DataTables API 實例,結果集中包含選定的按鈕,可用於對按鈕進行進一步的鏈式操作。

範例

啟用所有按鈕

var table = new DataTable('#myTable');

table.buttons().enable();

在邏輯條件上設定啟用狀態

var table = new DataTable('#myTable');

table
	.buttons(['.edit', '.delete'])
	.enable(table.rows({ selected: true }).indexes().length === 0 ? false : true);