How to get the visible columns?
How to get the visible columns?
eprozium
Posts: 9Questions: 3Answers: 0
Hi,
I might be missing something, but I can't find in the API how to get what columns are visible( and what columns are not), since the user can change that if the columns button is present.
https://datatables.net/reference/api/columns().visible()
does not seems to just "get" all visible columns.
Is there another API for this operation, or an example/fiddle/jsbin how to use it?
Thank you.
This discussion has been closed.
Answers
It returns an array of true/false for each column by column position. You can iterate through the array to get positions of the true (visible) columns. Is that what you want?
Kevin
Yes, but in this example:
http://live.datatables.net/gekamiqi/8/edit
in the console, the returned "array" it doesn't look like the simple reference array .
Its an array with the Datatables API. You can access it the same as an array. You can also use
toArray
to get the array without the API instance. See your updated example:http://live.datatables.net/fekegapo/1/edit
Kevin
@kthorngren thank you very much for your help.
From the user's perspective, would be much easier than when in server mode, DataTables would send this information too as parameters along the many other it already sends .
Not sure I understand, are you wanting the column visibility sent to the server script when using server side processing?
You could add this using
ajax.data
.Kevin
Yes, on the server too .
In client-side processing, if a column is set to invisible, it won't be present in client-side Excel Export, so:
when using server-side processing, this would be required information in order to be able to do a correct Excel Export .
Of course, not just for export, but for other operations too that need to be done by the server for a "correct" and uniform server-side processing.
Sounds like a good reason to add it. To add it as a parameter for server side processing would be a feature request for @allan to evaluate.
If you did use
ajax.data
to send the visible columns you would probably need to do something on the initial Datatable load since that API might not be available.Kevin