row().data()
自:DataTables 1.10 起
取得/設定選取列的資料。
說明
此方法用於處理透過 row()
選擇器所擷取的列資料。它可用於取得現有資料,或設定要用於列的新資料。
請注意,當用作設定器時,此方法會設定要套用至表格的資料,但不會更新表格的內部資料快取,直到呼叫 draw()
方法。這可以簡單地作為 row().data()
方法的傳回物件的鏈式方法來完成 - 例如 table.row( 0 ).data( newData ).draw();
。這樣做是為了方便表格的優化,以便在重新繪製表格之前可以套用連續的更新。
類型
範例
點擊時取得單列的資料
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'tr', function () {
console.log(table.row(this).data());
});
點擊列時增加計數器
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'tr', function () {
var d = table.row(this).data();
d.counter++;
table
.row(this)
.data(d)
.draw();
});
// Note that row().invalidate() could also be used for this example case
更新表格中的所有列,僅在完成時重新繪製
var table = new DataTable('#myTable');
table.rows().every(function () {
var d = this.data();
d.counter++; // update data source for the row
this.invalidate(); // invalidate the data DataTables has cached for this row
});
// Draw once all updates are done
table.draw();
相關
下列選項直接相關,也可能對您的應用程式開發有用。