How to use $.fn.dataTable.render.text on a columns without defining all columns?
How to use $.fn.dataTable.render.text on a columns without defining all columns?
Hello,
I am using dataTable on an HTML table that we have already with defined headers and body. I would like to use the function $.fn.dataTable.render.number without having to define all columns again like the example here:
https://datatables.net/manual/data/renderers
{
"product": "Toy car",
"creator": {
"firstName": "Fiona",
"lastName": "White"
},
"created": "2015-11-01",
"price": 19.99,
"cost": 12.53
}
Can I target the price column for example by mentioning the column number directly or do I have to redefine the entire table header scheme?
data: 3, <--Column number of price assuming starting with Column 0
render: function ( data, type, row ) {
return $.fn.dataTable.render.text(data)
}
Thank you
This question has accepted answers - jump to:
Answers
You can use
columnDefs
to assign renderers to specific columns using thetargets
parameter.Kevin
Would you be kind enough to write an example? I already have columnDefs defined for sorting but not sure how to apply $.fn.dataTable.render.text() function to all data in a column
Tried this but no luck
{ render: $.fn.dataTable.render.text(data), targets: 3 }
Also tried
will apply the text renderer to all columns. See the
columnDefs.targets
documentation for more information about the targeting options.Allan
Thank you! I was wondering if that is required if the backend already escapes HTML when displaying values? I'm using Jinja2 to be specific
I think this is rhetorical, but just to be explicit, no - the text renderer will do it for you.
Allan