{hero}

按鈕.按鈕.動作

自:按鈕 1.0.0 起

按鈕啟動時要執行的動作。
請注意 - 此屬性需要 DataTables 的 按鈕擴充功能。

描述

此屬性是功能屬性 buttons.buttons.action 的別名,可用於從頂層 DataTables 配置物件配置此功能,而不是在 layout 選項中(請參閱以下範例)。這讓您可以使用字串而不是物件來使用此功能,但如果您使用多個功能實例,則會限制配置。有關適用於此選項的完整詳細資訊和選項,請參閱 buttons.buttons.action 的文件。

如果您使用的是不包含 layout 選項的 DataTables 1.x,請使用此屬性名稱,但請參閱 buttons.buttons.action 的文件以了解完整詳細資訊。

範例

自訂動作函式

new DataTable('#myTable', {
	layout: {
		topStart: 'buttons'
	},
	buttons: [
		{
			text: 'Alert',
			action: function (e, dt, node, config, cb) {
				alert('Activated!');
				this.disable(); // disable button
			}
		}
	]
});

建立使用內建按鈕動作方法的自訂按鈕

new DataTable('#myTable', {
	layout: {
		topStart: 'buttons'
	},
	buttons: [
		{
			text: 'Create CSV',
			action: function (e, dt, node, config, cb) {
				// Do custom processing
				// ...

				// Call the default csvHtml5 action method to create the CSV file
				DataTable.ext.buttons.csvHtml5.action.call(this, e, dt, node, config, cb);
			}
		}
	]
});