DataTables with dynamic table
DataTables with dynamic table
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.
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.
This discussion has been closed.
Replies
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.
[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