Dynamically add columns rather than rows with AJAX callback

Dynamically add columns rather than rows with AJAX callback

m0smithm0smith Posts: 2Questions: 0Answers: 0
edited June 2011 in General
Hi all,

I have been working with DataTables for a short while and really like the many features and the examples of how to use them. It has made my job a lot easier. Thanks.

For my current project I need to have a table but with the row and column functionality inverted. The table needs to have a fixed number of rows and the number of columns may be dynamic. In this application each column represents a date and as the users scrolls, they see older and older data.

Adding an horizontal scroll bar is easy enough. However, I cannot find a way to dynamically add columns as the user scrolls. There is great support for adding dynamic rows from an AJAX callback but nothing for adding columns dynamically.

Does anyone have a suggestion for dynamically adding columns or are columns required to be fixed?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    This isn't a feature that DataTables currently has. At the moment once the table is initialised then the number of columns are fixed.

    There are two possible work arounds: 1 use column visibility - have a lot of columns and only show the columns you need, or 2. a plug-in could be written to dynamically add and remove columns.

    Having said that, the concept of the table having columns x rows rather than the other way around is deeply engrained into DataTables - for example you can do horizontal sorting or filtering, only vertical.

    So I'm afraid that DataTables is possibly not suited to that task.

    Allan
  • m0smithm0smith Posts: 2Questions: 0Answers: 0
    Thanks for the response. We are looking for another way to show the data.
  • cubenzcubenz Posts: 3Questions: 0Answers: 0
    edited July 2011
    Similar, but simpler.

    I want conditionally to add a check box on to each row (either all rows have a check box or not, depending on user's permissions).

    Can checkbox markup be included in the json data?

    Thanks
  • cubenzcubenz Posts: 3Questions: 0Answers: 0
    Update;

    I have found that adding the input to the json works:


    { "aaData": [
    [ "UP-019209","1/07/2011","Unrated","PPKAEOEX",""]
    ]}

    so the question is, is this the best way to do this, or should I use fnRender() or fnRowCallback() to achieve the desired result?
This discussion has been closed.