Multi-level grouping issues + modify data rows

Multi-level grouping issues + modify data rows

MarcoKMarcoK Posts: 4Questions: 0Answers: 0
edited July 2023 in Free community support

Hi,
I'm trying to implement multi-level grouping in my table and I'm close to succeed but would need help at this stage. My goal is to have Level 0 and 1 expanded and level 2 collapsed by default. That part works. However, there are 2 issues that I'm stuck with.
1) If I try to collapse Level 0, it reveals the data rows
2) I can't collapse Level 1

Also, instead of having the column headers at the top, I was wondering if it was at all possible to reveal the column headers just above the first data row if level 2 is expanded? For example, if I expand the first item "POLARCUP 51 NON-CEMENTED", Id like to have the header "Lot" just above "C2204677". Otherwise, it could also be "Lot: C2204677" as an acceptable option. Is that feasible?

https://live.datatables.net/migixiqi/899/edit?html,js,output

Thanks in advance for your help

Replies

  • allanallan Posts: 63,506Questions: 1Answers: 10,471 Site admin

    RoweGroup doesn't currently support collapsing of groups. That is something that I'd like to add in future. Sorry!

    Also, instead of having the column headers at the top, I was wondering if it was at all possible to reveal the column headers just above the first data row if level 2 is expanded?

    There isn't a trivial option for that I'm afraid. You could use rowGroup.startRender to do it though. You'd need to use the API to get the column headers and construct the tr for the row though.

    I can see that might be a nice option to add in future! Mildy surprised we've not come across that one before!

    Allan

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,953
    edited July 2023

    The code you have works for only two levels. Take a look at this example from this thread for code that seems to work with more than two levels.

    Kevin

  • MarcoKMarcoK Posts: 4Questions: 0Answers: 0

    Thanks Allan and Kevin for taking time and for your hints. Greatly appreciated. I'll give it a try.
    Marc

  • MarcoKMarcoK Posts: 4Questions: 0Answers: 0

    Hi gentelemen,
    I was able to use the code suggested by Kevin to fix my multi-level group collapse issue.
    Here's the link to my updated code
    https://live.datatables.net/migixiqi/917/edit?js,output

    Allan, I tried to implement your solution to add a header row but I think Ineed some pointers. I can't figure out how to add a row above the actual rows.data[0] and return the updated data;

    Thanks in advance
    Marc

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,953

    Maybe something like this:
    https://live.datatables.net/migixiqi/918/edit

    It uses columns().every() with the column-selector of :visible to get the visible column names and builds a jQuery row with those names as the header. It then uses jQuery add() to add the row to the rowGroup rows.

    There may be better ways to do this but should give you some ideas.

    Kevin

  • MarcoKMarcoK Posts: 4Questions: 0Answers: 0

    Kevin, that's exactly what I was looking for! What a great support from you guys. Thanks a lot

    Marc

Sign In or Register to comment.