Add column w/out pre-rendered DOM element
Add column w/out pre-rendered DOM element
Howdy all. I'm working on implementing a slight variation of the Row_Details example (http://datatables.net/release-datatables/examples/api/row_details.html), but I'm running into a problem because I'm loading data from an AJAX source instead of the DOM element as described. I tried just adding a new column to the DataTable after initialization, but this messed up rendering effects (when sorting, the wrong column is highlited and the auto-calculation feature for column width seems to get VERY confused by the new column).
I know that if I indicate a column with the mDataProp set to null, I can add a blank column which I could then populate on my own with the necessary icons and link in the correct event handlers. However, the blank column example breaks in its implementation if the FIRST column is the blank one, as the data does not match up correctly.
I don't think it'll be very efficient to try and add a null field to the incoming array for each row in my php handler file. Is there a way to do a custom mapping of the incoming JSON elements to the columns?
Example:
[code]
JSON = { "aaData : [["A1","A2","A3"],["B1","B2","B3"]]};
+----+-------------------+
| |Col0 Col1 Col2 Col3|
+----+-------------------+
|Row1|null A1 A2 A3 |
|Row2|null B1 B2 B3 |
+----+-------------------+
[/code]
I know that if I indicate a column with the mDataProp set to null, I can add a blank column which I could then populate on my own with the necessary icons and link in the correct event handlers. However, the blank column example breaks in its implementation if the FIRST column is the blank one, as the data does not match up correctly.
I don't think it'll be very efficient to try and add a null field to the incoming array for each row in my php handler file. Is there a way to do a custom mapping of the incoming JSON elements to the columns?
Example:
[code]
JSON = { "aaData : [["A1","A2","A3"],["B1","B2","B3"]]};
+----+-------------------+
| |Col0 Col1 Col2 Col3|
+----+-------------------+
|Row1|null A1 A2 A3 |
|Row2|null B1 B2 B3 |
+----+-------------------+
[/code]
This discussion has been closed.
Replies
DataTables doesn't currently support the dynamic addition of columns I'm afraid. The number of columns you initialise the table with, is how many it has for the lifetime of that DataTable.
> However, the blank column example breaks in its implementation if the FIRST column is the blank one, as the data does not match up correctly.
You are using arrays as your data source, so you need to also tell the other columns where to get their own data from, if you are going to offset the first column. For example:
[quote]
Column 1 - mDataProp: null
Column 2 - mDataProp: 0
Column 3 - mDataProp: 1
etc
[/quote]
Allan