Variable number of columns

Variable number of columns

MarcBorgersMarcBorgers Posts: 6Questions: 0Answers: 0
edited August 2011 in Feature requests
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.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I would like to see this as a feature as well. There's no reason why DataTables could not build dynamically if the column information is provided by an array, AJAX json, or intialization variables in aoColumns, etc.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Its not currently possible to do this in the DataTables core as it stands, but a plug-in which is capable of adding and removing columns is certainly possible to create, and on my to-do list.

    Regards,
    Allan
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    The DataTables visual wizard thingy I'm working on will also dynamically create table columns based on your data source. (but once it's specified, it will be written to a file and at that point, it's static and defined as per DT 1.8 requirements).

    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.
  • FlashJuniorFlashJunior Posts: 9Questions: 0Answers: 0
    that would be awesome!

    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
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited September 2011
    I haven't built much of it yet. Have a bit on my plate, and jobs that pay, so they take precedence.

    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.)
  • jp_noronhajp_noronha Posts: 59Questions: 0Answers: 0
    Glad to know that someone is also implementing a visual class to support datatables.

    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.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sounds awesome! I'm looking forward to seeing the results from you both ;-) !

    Allan
  • MPeter1975MPeter1975 Posts: 31Questions: 0Answers: 0
    Hi,

    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
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    No - I'm afraid I've not had the chance to be able to work on an API method that will allow columns to be added and deleted dynamically. Something that is still very much on to-do list, but I'm afraid that seems to be growing longer and longer!

    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
  • MPeter1975MPeter1975 Posts: 31Questions: 0Answers: 0
    Well. Allan, could you give me more information about this?

    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
This discussion has been closed.