ClassName as a function!

ClassName as a function!

FurburgerFurburger Posts: 37Questions: 8Answers: 0

Would it be possible to modify the className so it has a function option?

This would create tremendous flexibility.

Instead of this:

className: "text-right"

We could do something like this:

                    className: function render(data) {

                        return data.amount ? "text-right" : "text-center";
                        
                    },

This is a trivial example, but I have a number of more complex use cases where this would be very helpful.

Would it be possible?

Replies

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

    Yes, that could be done - nice idea. The changes would need to be here and here.

    I've filed an internal feature request for this.

    Allan

  • beneiftzbeneiftz Posts: 1Questions: 0Answers: 0

    any update on this one please?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    No, it's still in the same state (for my reference, this is DD-1347). We'll report back here when there's an update.

    Cheers,

    Colin

  • FurburgerFurburger Posts: 37Questions: 8Answers: 0

    Hi Colin

    Sorry to bug you but this has become quite important to a project I am currently working on. It would be very useful. Any chance you can fast track this?

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited January 2021

    Looks like you want to apply dynamic classnames based on the cell data. Maybe you already use this but createdRow or columns.createCell is used for this.

    The way columns.className works now is it applies the same class to the particular header and all the column cells.

    Kevin

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

    Making columns.className a function in and of itself is straight forward (it would be done here and also here for the header).

    What isn't so easy is the implications of this. If you change the data, there is currently no mechanism to update the class name for example.

    There are ways to manipulate the class dynamically as Kevin says though. So perhaps you could explain a little more about what you are looking to do so we can see how it will fit in with DataTables?

    Allan

This discussion has been closed.