columnDefs and multiple classNames

columnDefs and multiple classNames

paravisparavis Posts: 37Questions: 8Answers: 1

Hello,

I'm aware that the items at lower indexes in the columnDefs/classNames will take priority over anything found later on in the list.

However, my objective is to have DataTables assign 1 or more classes to a given column based on that column's title.

For example, consider the following columns: Charges_money_, Payments_money_, Collected_percent__center_ ...

I would like DataTables to assign the "dt-right" class to any titles with "money" in the name. And assign "dt-center" to anything with "center" in the name. But also, I would like to assign the class "charges" to anything that matches (case insensitive) "charges", and the class "payments" to any column title that matches "payments".

How can it be possible to achieve this without having to assign the class "dt-right charges" and "dt-right payments" as well as "dt-right"? My goal is to add the classes onto the previous if there are already assigned classes, not just take the lowest index class that matches that column.

Would this be a feature request or a bug fix? Or is it already possible with className options?

Thanks!
~Laz

Answers

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Hi Laz,

    Thanks for bringing this up. I can see that the behaviour you are looking for could be useful in some cases. It isn't currently possible and wasn't indented to work like that, so its a feature request.

    I'm a little concerned about backwards compatibility with this proposed change since the current behaviour can also be desirable in some cases, so I'm not sure that I will implement this, but I will consider it. It might be that a new property ("appendClassName" or similar) might be the way to approach this, depending on how much complexity / code it adds.

    Allan

  • paravisparavis Posts: 37Questions: 8Answers: 1

    Ah, yes I see. Backwards compatibility is most definitely important!

    With that in mind for the className option, another possibility could be a directive within that option called "appendClass" that defaults to FALSE, as well as an option called "allowOverwrite" that defaults to TRUE.

    That way backwards compatibility could be achieved along with controlling individual class attributes and giving/taking certain priority independent of the order.

    Just another idea. No idea how much work would be involved with that though ...

    We are putting together a DataTables+Shiny app, and our goal is to utilize the data's column names to assign classes, currency/percent, and other useful things.

    Anyhow, thank you again Allan, your work is great. :smile:

This discussion has been closed.