ClassName as a function!
ClassName as a function!
Furburger
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?
This discussion has been closed.
Replies
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
any update on this one please?
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
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?
Looks like you want to apply dynamic classnames based on the cell data. Maybe you already use this but
createdRow
orcolumns.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
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