Redraw for colvisgroup only once

Redraw for colvisgroup only once

LimpEmuLimpEmu Posts: 65Questions: 18Answers: 1

My table has a large number of columns. By default, I only display a small subset.

Using the button extension colvis, I am giving the user three options to change column visibility. Two colvisGroup buttons and one colvis button that allows control over the visibility of each column individually.

{
  extend: 'colvisGroup',
  text: 'Summary Columns',
  show: [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ],
  hide: [ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],
},
{
  extend: 'colvisGroup',
  text: 'Detail Columns',
  show: [ 3, 11, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44],
  hide: [ 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 45 ],
},
{
 extend: 'colvis',
 collectionLayout: 'fixed two-column',
 columns: ':not(.noVis)',
 postfixButtons: [ 'colvisRestore' ],
}

My table also highlights some cells' values if certain conditions are met via a rowCallBack. Whenever a user changes column visibility, I have to draw the table to ensure that the correct cell values are highlighted. Therefore I added an event handler for column-visibility.dt, but unfortunately for the colvisGroup it fires for each of the columns to be shown slowing down the display of the table.

$('#hrifcpq').on( 'column-visibility.dt', function ( e, settings, column, state ) {
    tablehrif.draw();
} );

I am looking for a modification to my event handler that would function more like this:

$('#hrifcpq').on( 'column-visibility.dt', function ( e, settings, column, state ) {
    if (user clicked on colvis button) tablehrif.draw();
    else if (user clicked on colvisGroup button) {if (column == hriftable[0].length-1-3) {tablehrif.draw();}}
} );

Is this possible?
Is there another way to trigger the rowCallBack besides listening to the column-visibility.dt event?

Please let me know if you have a suggestion, thank you!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,177Questions: 1Answers: 2,590
    Answer ✓

    Hi @LimpEmu ,

    As you say, there's no event to be able to differentiate what caused the visibility to change. Perhaps another approach would be to place the event on the button itself, using buttons-action.

    Cheers,

    Colin

  • LimpEmuLimpEmu Posts: 65Questions: 18Answers: 1

    Hi Collin:
    That works perfectly, exactly what I needed.
    Thank you!
    Beate

This discussion has been closed.