How to dynamically change column.class?

How to dynamically change column.class?

mbaasmbaas Posts: 67Questions: 24Answers: 1

I've written a "column-visibility"-handler to zebra-strip columns (they get default-styles assigned to them, but as I am using buttons.colwiz user may change the displayed columns and I always want their styling to be correct.
The core of my handler is

if (this.visible()){
 this.nodes().to$().removeClass("oddCol evenCol").addClass(even?"evenCol":"oddCol");
 even=!even;
}

This is working nicely...except that the headers do not change. So, I tried this.header() - but that only returns the HTML of the header, whereas nodes() does return nored that I can work on.
So I am wondering if I am using the different approach altogether???

Basically, the idea is that columns are initialized with a class: "odd" or "even"...and I want to change that (depensing on the visibility of the columns) before redrawing the table (with a different selection of columns). Could I achieve that easier?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Answer ✓

    There is no option to dynamically change it I'm afraid. This is one of the options where you'd need to destroy the table and then create a new one to change the configuration.

    Could you use just CSS to do what you need:

    tr td:nth-child( odd ) {
      ...
    }
    
    tr td:nth-child( even ) {
     ...
    }
    

    Allan

  • mbaasmbaas Posts: 67Questions: 24Answers: 1

    Thanks, I had not thought about that. Will try to use CSS then.

This discussion has been closed.