Using buttons ColVis along with Grouping/Summing Rows

Using buttons ColVis along with Grouping/Summing Rows

RobinSRobinS Posts: 11Questions: 4Answers: 1

Hi All - I'm adding grouping/summing rows through a drawcallback via manual HTML <tr><td></td></tr>, etc. using $(rows).eq( i ).before(rowHTML). This works fine, except when I use ColVis to show/hide columns it doesn't remove the grouping row <td>s, but it removes everything else fine. Is there a classname that I should be using on these <td>s so they're also removed? Or a callback I can use?
It appears there isn't a customize function, and I tried stateChange, but that wasn't firing. Curious if anyone else has solved this.
Thanks!

Answers

  • RobinSRobinS Posts: 11Questions: 4Answers: 1

    Just after posting I found column-visibility:
    https://datatables.net/reference/event/column-visibility

    In case anyone else is looking for the same, I ended up doing this:

          element.on( 'column-visibility.dt', ( e, settings, column, state ) => {
            const groupRows = $(element).find('tr.group');
            $(groupRows).each((index) => {
              const groupRow = groupRows[index];
              if (state) {
                $(groupRow).find('td:eq(' + column + ')').show();
              } else {
                $(groupRow).find('td:eq(' + column + ')').hide();
              }
            })
          } );
    
  • sergio0897sergio0897 Posts: 1Questions: 0Answers: 0

    Thank you so much! that code was very helpful for me c:

This discussion has been closed.