DataTables with dynamic table

DataTables with dynamic table

JQ_NoobJQ_Noob Posts: 6Questions: 0Answers: 0
edited October 2011 in General
Hi

I just wanted to know whether DataTables supports a dynamic backend table structure? The examples seem to specify table structure explicitly beforehand. What I would like is to have the number of columns in the DataTable be based upon the number of items inside an array that I wish to display.

For example:
Tom: 5'0, 125, 25
Joe: 5'10, 160, 34

If the above is my array of arrays, then I would like 2 rows with 4 columns displayed.

Please let me know if there is any such example

Thanks.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    not in DataTables.

    this is not to say that it can't be done. you'll just have to have a routine or ajax call that queries the schema, then build the table (mostly just need to get the right number of columns), then populated with data using DataTables' methods.
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Yup. If your application is written such that aoColumns can be trusted, you can even get the number of columns from there. But it would be up to you to build the table creation portion with DataTables' current implementation.
  • jkrobbinsjkrobbins Posts: 32Questions: 3Answers: 0
    I'm working on just such an app. I don't know what results will be displayed until run-time. Here's what I did. Create your table in the html or jsp like this:
    [code]








    [/code]

    Now you need to get the table headings. I use ajax and return the headings as a string of td's. The servlet does this:
    [code]
    Class<?> daoName = Class.forName(daoNeeded);
    Object newDAO = daoName.getDeclaredConstructor(DataSource.class).newInstance(ds);
    Method columnsMethod = daoName.getDeclaredMethod("getColNames", (Class<?>[]) null);
    columnNames = (List) columnsMethod.invoke(newDAO, (Object[]) null);
    StringBuffer colsAsHTML = new StringBuffer();
    for (int i=0;i
This discussion has been closed.