Column Display
Column Display
D R Neal
Posts: 3Questions: 1Answers: 0
Is it possible to show only one column of a table initially, using the search box to call the other columns one at a time/replacing the previous column? So that only one column is shown at a time.I have a list of Cities with data in the columns beneath each city. We would like for employees to be able to search for only their city's information. I am writing the table dynamically with php and mySQL. Thanks.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It is not clear to me what exactly you want but you will certainly find some hints here:
https://datatables.net/reference/api/column().search()
https://datatables.net/reference/api/search()
https://datatables.net/reference/api/column().visible()
Based on events you should be able to dynamically hide and show columns. I do that all the time with entire child tables.
https://datatables.net/reference/event/
You can dynamically control the visibility of columns using
column().visible()
- but there is currently no way to dynamically add and remove columns from the data modal of the DataTable.You could listen for the
search
event and update the visible columns based on the current state.Allan
I asked my question and promptly left on vacation.
To clarify my query, this is my working table:
http://www.tmrs.com/table_flip_new.php
The search box searches by row and not by column.
I would like to be able to search the column headers to display a specific city.
Thanks!
Why not just add the City as an hidden value for each column and then it can be searched from there?
DataTables' doesn't have built in support for search to search across columns and dynamically remove columns like you are looking for. But it would be quite possible to build your own search and use the
column().visible()
method to show / hide the columns as required by the input search value.Allan