Get value of attribute
Get value of attribute
StijnQCA
Posts: 8Questions: 2Answers: 1
Hello all,
I have an application in which each column has to be formatted differently. I use render in the following way:
columnDefs: [
{
targets: "_all",
render: function (data) {
return window[?????](data);
}
}
],
On the position of the questionmarks i would like to have the value of an attribute; data-??? (the name doesnt really matter)
What attribute can I use for this?
Even better would be to have:
<th data-render="function"></th>
Is there any way to do this?
Thanks
This discussion has been closed.
Answers
Hi @StijnQCA ,
Not sure if this what you're looking for, but you can give each column a unique class with
columns.className
. That would allow you to then set CSS formatting rules for each.Hope that helps,
Cheers,
Colin
Hey @colin
Thanks for the quick reply.
I want to use a function for each column that formats the cell in a specific way.
For example the status column should be formatted like:
Unfortunately this is not achieved by setting the
columns.className| Option
.Hi StijnQCA, I think that you may want to use the created row callback and then apply a class to the cell. Say your column is in the 4th position.
I don't know if this can work I haven't tested it.
Hi again,
Yep, that's just for the CSS class. If you want to do more, and change how it looks, you can use
columns.render
, and thedisplay
option. Take a look at this example - it changes the column into a URL and truncates with ellipses.Hope that's the one you're after!
Cheers,
Colin
I ended up adding the value to the data object like:
this way the formatter used depends on what is retrieved from the server.