RowGroup grouping works correctly on one source, incorrectly on another

RowGroup grouping works correctly on one source, incorrectly on another

kconradkconrad Posts: 5Questions: 2Answers: 1

I've got a table that I want to be able to group by different columns, based on User Input. I've started using the RowGroup plugin since this is pretty much exactly what I was looking for, and also found a way to expand/collapse the groupings.

My issue is that for one of the specific groupings, the grouping mechanic doesn't actually function properly, and creates multiple groups when I believe it shouldn't be doing so. The data comes in from the server, so I'm able to apply a .trim() function on the strings in the selected column for grouping.

Below is a link to a copy of my table with the DataTables code that I have implemented, with the only difference being that my version of DataTables is actually 1.10.16, whereas the version used here is 1.10.21-dev - Since I copied in the rest of the code and it worked the same way, I opted to leave the version as it was.

http://live.datatables.net/layudizi/1/edit

If you swap between dataSrc: 4 (problem) and dataSrc: 0 (working properly) you'll see how when grouping by Column 4 (Customer) it will create multiple groupings with the same Customer Number, but when you group by Column 0 (Item Code) there is one group per code. Have I missed something?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    The rowGroup.dataSrc determines which field is used for the grouping. Your field 0 is unique, so no grouping can happen when it's set to that. 4 is your customer field, so many records share that same customer, so they are grouped together.

    4 (problem) and dataSrc: 0 (working properly)

    Is that back to front? Isn't 4 what you're after - or am I getting myself confused.

    Colin

  • kthorngrenkthorngren Posts: 21,171Questions: 26Answers: 4,922
    Answer ✓

    Your primary sorted column needs to be the rowGroup.dataSrc column. Something like this:
    "order" : [[4,'asc'], [0, 'asc']]

    At I high level I think the RowGroup extension processes the rows in sorted order to build the groups. When the dataSrc column value changes it creates a new group. If the primary sort is not this column then you can end up with the split groups you are seeing.

    Here is the updated example:
    http://live.datatables.net/layudizi/4/edit

    Kevin

  • kconradkconrad Posts: 5Questions: 2Answers: 1

    @kthorngren Thank you for your response! This does in fact seem to be the case. I had also posted the question over on Stack Overflow and they have arrived at the same conclusion as well. It's one of those things I didn't think to try, unfortunately.

This discussion has been closed.