Reputation: 311
I have a dataset with child columns. How can I emulate using datatables.js?
Ex:
+-------+----------------------------+-----------+
| Name | Marks | Rank |
| +---------+----------+-------+ |
| |Internal | External | Total | |
+-------+---------+----------+-------+-----------+
| Sandy | 24 | 55 | 79 |Distinction|
+-------+---------+----------+-------+-----------+
| Bill | 13 | 25 | 38 | Fail |
+-------+---------+----------+-------+-----------+
Currently I am using this, but when I save the table as csv / xls, I get
+------------------------------------------------+
| Name |Internal | External | Total | Rank |
|------------------------------------------------|
| Sandy | 24 | 55 | 79 |Distinction|
|------------------------------------------------|
| Bill | 13 | 25 | 38 | Fail |
+------------------------------------------------+
But we have an option of adding child rows.
Is there any way to have child columns? Or can we divide a column?
Upvotes: 1
Views: 256
Reputation: 6165
You can emulate the structure, but not the layout. A JSON logical equivalent of your data would be:
[{
"Name": "Sandy",
"Marks": {
"Internal": "24",
"External": "55",
"Total": "79"
},
"Rank": "Distinction"
}, {
"Name": "Bill",
"Marks": {
"Internal": "13",
"External": "25",
"Total": "38"
},
"Rank": "Fail"
}]
The way you might set this up using the child table trick in the link is to put Name, Rank and Marks in the table, and when you click on a line to open it, you'll see Internal, External and Total as "child rows" in the embedded table.
I suspect that what you are doing to get the layout you have is putting two rows in your header. I don't know Excel well enough to know whether or not this JSON structure will import in such a way as to automatically give you the layout you want. If it does, perhaps you can consider some sort of hack where you prepare one structure for the table and another for the Excel.
Upvotes: 1
Reputation: 2594
Unfortunately, this is not possible with the current version of DataTables. See this question on the DataTables forums.
There is no option for that at the moment. Sorry.
Allan
From the creator of the plugin.
You noted in a comment that it is possible in excel to make these tables, but with the current version of DataTables there is no way to automatically export your DataTable in this format.
Edit: Here's a much more recent forum post confirming that this feature is not available.
Upvotes: 1