Column Visibility Groups with Row Grouping and Aggregates

Column Visibility Groups with Row Grouping and Aggregates

dougguthriedougguthrie Posts: 10Questions: 7Answers: 0

I'm having an issue getting the column visibility groupings to work with row groups. The aggregates in the grouped row shift when I change the visibility of the column groups. I used this example to get my visibility groups: https://datatables.net/extensions/buttons/examples/column_visibility/columnGroups.html. I used this example to render aggregates in my grouped row: https://datatables.net/extensions/rowgroup/examples/initialisation/customRow.html. I can't seem to get them to work together. I've created a fiddle that you can view here: https://jsfiddle.net/9kb5caeg/2/. Any help would be appreciated.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948
    Answer ✓

    Thanks for the example. The only thing I can think of is to check the column visibility when appending the td and only append "" if its not visible. For example:
    append( table.column(6).visible() ? '<td class="text-center">' + one + '</td>' : '' )

    You will need to get an instance of the Datatables API. I did this at the beginning of the startRender function. It also looks like you will need to force a table draw() to recalc the RowGroup. This can be done in the column-visibility event (at the end of my example).

    Here is the updated example:
    https://jsfiddle.net/j4x2tvw1/

    Maybe someone will provide a better alternative.

    Kevin

  • dougguthriedougguthrie Posts: 10Questions: 7Answers: 0

    Thank you for the answer! This seems to do the trick

This discussion has been closed.