Variable number of columns
Variable number of columns
MarcBorgers
Posts: 6Questions: 0Answers: 0
I want to use DataTables with variable number of columns: the number of columns is not fixed, it is read from the server as well. There is no direct support for it in datatables. The solution I have is the following: I fetch (ajax) the columns and add them via jquery to the table. Then I fetch the rows (in a second ajax request). In order to be able to fetch different data this way, I wrap the table in a div and on refersh, I clear the whole div ((so deleting the included datatable) and build the table up from scratch.
It would be nice have some support for this kind of use.
It would be nice have some support for this kind of use.
This discussion has been closed.
Replies
Regards,
Allan
There's a blog entry at http://tote-magote.blogspot.com/2011/08/datatables-work.html which briefly summarizes this project, currently named VisualDT.
I've got a tinymce install that I've added a "json" plugin to convert back and forth between valid DataTables JSON and a TABLE, accomplishing the dynamic table creation (the user will get to choose which format they want to use in their final code: html, array, ajax-json, or db-source). Will add a few more data source options to tinymce and then move onto phase 2.
Has somebody build a plugin already?
Important for me is that i also should be able to defined
- aoColumns //for sorttype and classes
- aaSorting //for sorting
The finished product will allow specifying initial data as: html table, array, ajax/json array, database, csv, and to switch between them if you change your mind.
The wizard will have a visual object properties window, similar to Visual Basic and other visual IDE's (see http://www.beg.utexas.edu/_work/dt/propertieswindow.htm for a test sample). You will be able to use these object properties windows to define the init object (and set aaSorting, etc) and aoColumns/aoColumnDefs, with all the available parameters laid out (and sortable/filterable) before you.
If anyone is interested in helping code this, that would be awesome, since I've been too busy to work much on it. (I hope this will change in about a week, as I finish a project I'm on.)
Mine is almost finish, just a few cuts and trimm some wild bugs that come from time to time :)
i´m not ambitious as fbas (hope he can do what says and more), i just want a visual class with a wrapper to datatable, injecting jquery scripts and files in the backgroud. the developer don´t have to know any jquery to use.
The main purpose is to serve a team of developers.
Allan
Any news on dynamic column creation?
I have a table which has unpredictable number of columns at the beginning. User selects a time period and one column must be shown for each months in the period, so the number of columns is based on the user's selection. All the data processing would be on server side so I need to add/remove columns on a fnDraw() call. Is it possible now with DataTables 1.9?
Any help welcome!
Peter
All I can offer as a suggestion with the way DataTables currently is, is to find out how many columns there are first (perhaps a different Ajax call, or make your own Ajax call and then feed the data into the DataTable using aaData so it doesn't make its own Ajax call).
Allan
How can I make my own ajax call to define the number of columns and then build the table? Could you point me to an example like this?
Thanks!
Peter