RowGroup with custom groups
RowGroup with custom groups
Link to test case: http://live.datatables.net/hubicona/1/edit
Debugger code (debug.datatables.net): N/A
Error messages shown: N/A
Description of problem: I would like to have my rows grouped in two levels, but I want these groups to be customized from the imported data. In this example, we customize the data to display but NOT the data that is calculating the groups. I know there are many ways to change the display data, but I need to change the data before it calculates groups.
This worked fine as I followed the example here: https://datatables.net/extensions/rowgroup/examples/initialisation/range.html the dataSrc can accept a function, allowing a user to customize how the groups are grouped. The issue is I would like to utilize that functionality while still being able to pass an array of multiple groupings. To extend my provided example, imagine I want to group these people by Position but I want to combine Developer and Javascript Developer PLUS I want to have sub-groups by Salary for a range of salaries.
Is this possible? All my testing has lead me to believe that it may not be, but I'd love to see someone solve this!
This question has an accepted answers - jump to answer
Answers
I don’t quite get this I’m afraid. If you are grouping by Position the Developer and Javascript Developer would be different groups. Perhaps the data needs to be normalised in some way here - so the Javascript developer is actually just a Developer?
Allan
Yes exactly, using dataSrc: function() I am able to normalize the data as the groups are being formed, but only on a single level.
Take a look at https://datatables.net/extensions/rowgroup/examples/initialisation/range.html it has an example of how I'm using the dataSrc function to group. This works totally fine on a single level but I cannot reproduce the multi-level grouping that can be achieved by providing dataSrc an array.
I'd prefer not to modify the data prior to the grouping, as my data set can be quite large and I do not have the ability to customize the information being given to it, so I would need to utilize javascript to loop over the entire data set creating extra properties for the normalized data. I would much rather do this during the grouping process.
For multiple groups the
rowGroup.dataSrc
option is an array. Have you tried returning an array of functions that represent your nested groups? For example:http://live.datatables.net/hubicona/3/edit
Kevin
Awesome! I was trying a single function returning an array, but an array of functions works perfectly! Thanks you very much!