buttons.buttons.async
自:Buttons 3.0.0 起
表示按鈕的動作處理應該以非同步方式執行。
請注意 - 此屬性需要 DataTables 的 Buttons 擴充功能。
描述
對於需要顯著時間的動作,您可能希望為觸發該動作的按鈕顯示處理指示器。按鈕可以使用 button().processing()
方法來實現這一點,但它需要在 JavaScript 執行中斷,才能夠在頁面上顯示處理指示器。
此選項正是提供了該選項,指定在顯示處理指示器後多少毫秒應該執行動作。
指定後,您必須呼叫傳遞給 buttons.buttons.action
函式的回呼函式作為第五個參數,以表示處理已完成 (即當您的非同步動作完成時)。這會從按鈕中移除處理指示器。
類型
預設值
- 值:
無預設值 (即未定義)
範例
非同步處理完成回呼
new DataTable('#myTable', {
layout: {
topEnd: {
buttons: [
{
text: 'Make Ajax call',
async: 100,
action: function (e, dt, node, config, cb) {
// Do custom async processing - e.g. an Ajax call
new Promise(resolve => {
// ...
resolve();
cb();
});
}
}
]
}
}
});