Adding CSS styling to hidden columns

Adding CSS styling to hidden columns

Dhan13Dhan13 Posts: 2Questions: 1Answers: 0
edited November 2020 in Free community support

Hi, I'm using DT editor and modify row borders as below. However, there are some columns in my table, hidden by default, that I can toggle them back to be visible. Those columns' cells do not get the css styling as the other cells. What could solve this?

Code:

"createdRow": function( row, data, dataIndex ) {
            //console.log(data);
           // $(row).css('border', 'solid 1px red');
            if ( data['coverage'] == 'Uncovered' || data['coverage'] == 'uncovered') {        
                $(row).addClass('red'); 
                $('td', row).css({'border-bottom': '1px solid black'});
                  
            }else if ( data['stat'] == 'warn' ){
                $(row).addClass('amber');
                $('td', row).css({'border-bottom': '1px solid black'});
                //console.log('ok');
            }else if ( data['stat'] == 'alert' ){
                $(row).addClass('orange');
                $('td', row).css({'border-bottom': '1px solid black'});
                //console.log('ok');
            }else{
                $(row).addClass('grey');
                $('td', row).css({'border-bottom': '1px solid black'});
            }

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited November 2020 Answer ✓

    Likely the $('td', row) selector doesn't find the hidden columns. The createdRow callback runs only once when the row is created. Try using rowCallback instead, it is run each time the table is drawn. You should just need to change createdRow to rowCallback in line 1.

    Not sure how you are making the column visible but you will need to make sure the table is redrawn. You can use draw() if needed.

    Kevin

  • Dhan13Dhan13 Posts: 2Questions: 1Answers: 0
    edited November 2020

    Hi, I'm using the 'colvis' button and 'columndefs' for defining columns. How may I use the 'draw' API in such situation? is there another listener or API to capture this event? Thank you.

     "columnDefs": [
        { "visible": false, "targets": 5 },
        { "visible": false, "targets": 8 },
        { targets: 9,className: 'noVis'}
    ]
    

    and

    {extend: 'colvis',columns: ':not(.noVis)'},
    
  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    Answer ✓

    Try the column-visibility event.

    Kevin

This discussion has been closed.