資料
自:DataTables 1.10 起
用作表格顯示資料的資料。
描述
DataTables 可以從多個來源獲取要在表格主體中顯示的資料,包括使用此初始化參數作為列資料陣列傳入。與其他動態資料來源一樣,可以使用陣列或物件作為每列的資料來源,並使用columns.data
從特定物件屬性讀取資料。
當從 Javascript 資料來源或自訂 Ajax 資料獲取建立表格時,使用此初始化選項會很有用。
請注意,如果指定了 data
,則陣列中提供的資料將取代初始化時在表格 DOM 中找到的任何資訊。
類型
此選項可以使用以下類型
範例
使用二維陣列資料來源
new DataTable('#myTable', {
data: [
[
'Tiger Nixon',
'System Architect',
'$3,120',
'2011/04/25',
'Edinburgh',
5421
],
['Garrett Winters', 'Director', '$8,422', '2011/07/25', 'Edinburgh', 8422]
// ...
]
});
使用物件陣列作為資料來源
new DataTable('#myTable', {
data: [
{
name: 'Tiger Nixon',
position: 'System Architect',
salary: '$3,120',
start_date: '2011/04/25',
office: 'Edinburgh',
extn: 5421
},
{
name: 'Garrett Winters',
position: 'Director',
salary: '5300',
start_date: '2011/07/25',
office: 'Edinburgh',
extn: '8422'
}
// ...
],
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'extn' },
{ data: 'start_date' },
{ data: 'salary' }
]
});
相關
以下選項直接相關,也可能在您的應用程式開發中很有用。