columnDefs.targets by class name not working when columns defined in JS
columnDefs.targets by class name not working when columns defined in JS
In a project I am working on, the HTML is simply an empty table. The data and columns are sent from an external ajax call. The columns are all assigned classes using className. When I try to add custom rendering to those columns using columnDefs, I am unable to use the classname of the column as the "targets". I have to specify the columns by index number. Is that working as intended?
I created a demo of the issue at http://live.datatables.net/sisigaca/1/edit The first table has columns defined by JS, and the second table has columns defined in HTML, and you can see that the Age column is formatted "properly" in the second table but not the first. I tried to make the example as close to my production environment as I could using sample data.
This question has an accepted answers - jump to answer
Answers
Interesting. I couldn't make it work either. But here is a solution replacing "className" in "columns" with "render". That works!
The problem here is that the
columnDefs
are actually applied before thecolumns
(allowing the more specificcolumns
to override anything set by thecolumnDefs
).This is a limitation of the
columnDefs.targets
, no question. I haven't yet worked out a nice way of resolving it I'm afraid.Allan
Any updates about columnDef.targets should be column title instead of column index?
No - this isn't likely to come until v2 I'm afraid.
Allan