{hero}

get()

自:DataTables 2.0.0 起

從 DataTable 實例取得底層資料。

描述

這個方法提供存取 DataTables API 實例中包含的資料。DataTables API 是類陣列的,因此可以使用陣列表示法來存取資料,但使用 API 更明確地陳述程式碼中發生的情況也很有用(即,使其更具可讀性)。它基於同名的 jQuery 方法

請注意,此方法最初可能看起來與 eq() 方法相似,但這兩個方法操作的資料是不同的

  • eq() 從引用多個表格的 API 實例中選擇特定的 DataTable
  • get() 從 API 實例中取得資料。

類型

function get( idx )

描述

從 DataTables API 實例中的給定索引取得資料。

參數
返回

任意

來自給定索引的資料。如果給定索引處不存在資料,則返回 undefined

範例

取得第二欄頂部儲存格的資料,並考慮目前的排序

var table = new DataTable('#myTable');
var cellData = table
	.column(2, { order: 'applied' })
	.data()
	.get(0);

// Note that the above is functionally the same as:
// table.column(2, {order: 'applied'}).data()[0]

取得表格中第一列的資料

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

table
	.rows()
	.data()
	.get(0);

// Again, this is functionally the same as:
// table.rows().data()[0]

相關

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