I am using a "fnDrawCallback" in Datatables to get the all column headers names () for that I am using the code below
"fnDrawCallback": function () {
table.column().every( function () {
var data = this.data();
var title = table.columns().header();
console.log($(title).html());
} );
I can get the column header name for first column . I want to know how can I iterate through all columns in table and get all the header () name?
The simplest way I know to do this is with some jQuery inside the
drawCallbackoption:I am using the more recent
drawCallback, not the older legacyfnDrawCallback(but both do work).Just to note: In your question, you are using
table.column().every( function () {...}. I can't see how you are defining yourtablevariable, in your example. So if my suggested approach is not suitable, perhaps you can edit your question to show the context in which you are usingfnDrawCallback.Update
If you want to hide one or more columns based on the names of the column headings, then you can take the above code and modify it as follows:
In the above example, I have a table where the "Office" and "Age" columns are hidden when the table is drawn.