{hero}

建立

自:Editor 1.5.0 起

一個使用 Editor 建立新列的按鈕。
請注意 - 此屬性需要 DataTables 的 Editor 擴充功能。

描述

create 按鈕類型由 Editor 提供,並提供一個易於使用的介面來呼叫 create() 方法,透過預先定義的按鈕。所有可用的 create() 方法的表單選項,都可以透過按鈕選項來設定(即 formButtonsformMessageformTitle)。

此按鈕需要設定 editor 選項,這會告訴按鈕在啟用時要操作哪個 Editor 實例。這樣,如果需要,可以將多個 Editor 實例附加到單個 DataTable。

選項

除了所有按鈕可用的選項(例如 buttons.buttons.text)之外,此按鈕還可以在其配置物件中設定以下選項,來自訂其動作和顯示。

範例

針對 Editor 實例 myEditor 的單個簡單 create 按鈕

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor
		}
	]
});

建立、編輯和移除按鈕,全部使用預設選項

new DataTable('#myTable', {
	buttons: [
		{ extend: 'create', editor: myEditor },
		{ extend: 'edit', editor: myEditor },
		{ extend: 'remove', editor: myEditor }
	]
});

具有取消按鈕的建立按鈕

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor,
			formButtons: [
				{
					label: 'Cancel',
					fn: function () {
						this.close();
					}
				},
				'Create new row'
			]
		}
	]
});

具有自訂訊息的建立按鈕

new DataTable('#myTable', {
	buttons: [
		{
			extend: 'create',
			editor: myEditor,
			formMessage:
				'Enter the data for the new row and click the "Save" button below to save permanently.'
		}
	]
});

相關

以下選項直接相關,在您的應用程式開發中也可能很有用。