row().index()
始於:DataTables 1.10
取得所選取列的列索引。
說明
DataTables 會將列和行的資料儲存在內部索引中,以便快速排序、搜尋等。有時知道這些索引是很有用的,因為它們可以用於 row()
、column()
和其他使用選取器的 API 方法中的有效選取器。
此方法用於檢索所選取列的索引,然後這些索引可以用作選取器的一部分來更新資料。
類型
範例
顯示點擊列索引的警示
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'tr', function () {
alert('Row index: ' + table.row(this).index());
});
使用所選取的列作為 cells()
選取器的一部分。
var table = new DataTable('#myTable');
$('#example tbody').on('click', 'tr', function () {
var idx = table.row(this).index();
table
.cell(idx, 0) // note that you could actually pass in 'this' as the row selector!
.data('Updated')
.draw();
});
相關
以下選項直接相關,在您的應用程式開發中可能也很有用。