Is there a way with the jquery datatables plugin to hide (and show) a table column?
I figured out how to reload the table data: using fnClearTable
and fnAddData
.
But my issue is that in one of my views for the table (e.g. a hidden mode) I don't want to show certain columns.
Hope this will help you. I am using this solution for Search on some columns but i don't want to display them on frontend.
With the api you can use
Look this info:
enter link description here
You can hide columns by this command:
Where first parameter is index of column and second parameter is visibility.
Via: http://www.datatables.net/api - function fnSetColumnVis
take look at my solution
I have this HTML
table Head
and my
Ajax request
returned something like thisso I want to hide Id index [0] and RegistrationStatusId index [5]
I hope this would help you
Note: the accepted solution is now outdated and part of legacy code. http://legacy.datatables.net/ref The solutions might not be appropriate for those working with the newer versions of DataTables (its legacy now) For the newer solution: you could use: https://datatables.net/reference/api/columns().visible()
alternatives you could implement a button: https://datatables.net/extensions/buttons/built-in look at the last option under the link provided that allows having a button that could toggle column visibility.