Should be simple: cannot change columns!
Should be simple: cannot change columns!
I am absolutely banging my head against the wall on this one and would greatly appreciate help. It seems like it should be so simple! And yet I can't even figure out what approach I should use.
Basically, I am developing an intranet site that will allow users to search and display tables of data. It seems like DataTables should be an elegant and ideal solution for this problem, and indeed up until this point it has been. Users enter search criteria and then I instantly display the results nicely formatted: searchable and sortable through DataTables. I use AJAX calls to retrieve an 2D array of data (externally from dataTables) and then I update the dataTables with fnFillData(). So far so good.
The problem is that users can search for more than one type of data. If I am searching inventory I get one table of data. But if I am searching orders I need to be able to display a different table. This seems elementary and yet I am completely stumped. I am so stumped that I will not show you code because I have no idea if anything I have coded is heading in the right direction. Certainly nothing works.
Fundamentally I either need to be able to show two different tables with completely different columns of data, or alter the columns of a single table. Either solution is acceptable to me, but I can't figure either one out, nor can I find concrete examples of either.
I cannot persuade the DataTable to completely reinitialise so I can simply fill it with new columns and data. I always run into the problem where there is a mismatch between the number of columns in the data and the number of columns in the DataTable, which apparently does not go away.
I also cannot make the table simply have columns for all possible fields and simply hide the ones not in use.
I have downloaded version 1.7 of this jquery plugin in hopes that it would present a solution (I was optimistic about the ability to Destroy a table and start over) but so far it has not.
Any help, especially in the form of concrete examples or code, would be dearly appreciated! I am sure there is a solution and am frustrated that I cannot seem to reach it.
Basically, I am developing an intranet site that will allow users to search and display tables of data. It seems like DataTables should be an elegant and ideal solution for this problem, and indeed up until this point it has been. Users enter search criteria and then I instantly display the results nicely formatted: searchable and sortable through DataTables. I use AJAX calls to retrieve an 2D array of data (externally from dataTables) and then I update the dataTables with fnFillData(). So far so good.
The problem is that users can search for more than one type of data. If I am searching inventory I get one table of data. But if I am searching orders I need to be able to display a different table. This seems elementary and yet I am completely stumped. I am so stumped that I will not show you code because I have no idea if anything I have coded is heading in the right direction. Certainly nothing works.
Fundamentally I either need to be able to show two different tables with completely different columns of data, or alter the columns of a single table. Either solution is acceptable to me, but I can't figure either one out, nor can I find concrete examples of either.
I cannot persuade the DataTable to completely reinitialise so I can simply fill it with new columns and data. I always run into the problem where there is a mismatch between the number of columns in the data and the number of columns in the DataTable, which apparently does not go away.
I also cannot make the table simply have columns for all possible fields and simply hide the ones not in use.
I have downloaded version 1.7 of this jquery plugin in hopes that it would present a solution (I was optimistic about the ability to Destroy a table and start over) but so far it has not.
Any help, especially in the form of concrete examples or code, would be dearly appreciated! I am sure there is a solution and am frustrated that I cannot seem to reach it.
This discussion has been closed.
Replies
1. You can use fnSetColumnVis ( http://datatables.net/api#fnSetColumnVis ) to show and hide the specific columns you want in a table. This would mean that your single table will need to include all of the columns needed for your 'virtual tables'
2. Use the destroy option of DataTables 1.7 - you say you tried this but couldn't get it to work. What did you try, and how did it not work. To destroy the table just call fnDestroy, and the table will be returned to it's old state - which might or might not be what you want.
3. Show and hide different tables (display:none) based on which one should be shown.
And probably a few others I can't think of off the top of my head :-)
Allan