数据表图像->当我尝试像这样获取标题名称时.. 然后我只得到了第一列名称,即NAME...但是我需要获取所有标头名称。如何获取所有标头名称?
this.api().columns().every( function ($i) {
var column = this;
var order = this.order();
var title = this.column(order[0][$i]).header();
var tt = $(title).html();
console.log(tt);
})
似乎有点过于复杂了:
this.api().columns().every(function() {
console.log( this.header().textContent )
})
会做"把戏"。
这对我来说很有效:
table.columns().header().map(d => d.textContent).toArray()
Alert the name of the column for a cell that was clicked on:
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'td', function () {
var idx = table.cell( this ).index().column;
var title = table.column( idx ).header();
alert( 'Column title clicked on: '+$(title).html() );
} );
var dataTableHeaderElements = $('#tableId').DataTable().columns().header();
var headers = [];
for (var i = 0; i< dataTableHeaderElements.length; i++) {
headers.push($(dataTableHeaderElements[i]).text())
}