Wondering how to use the built in date render (or number) from a custom render function
Wondering how to use the built in date render (or number) from a custom render function
I have a function defined in the render attribute of a column, which will go through some processing to determine the data type... Long story short.. I don't know the data type ahead of time, this function will determine if I will display a date, a boolean value, string, etc...
I saw in the release notes that date and number rendering are now built in. So I was hoping to alter my code to use the built in render once I determined the column is a date for example...
In the example documentation I can see that from the render attribute I could simply set render to DataTable.render.date().
however in my case I have a function defined... how do I call the render.date() function from within my own function... or can I not do that?
I tried accessing it via passing the render params in my function like so:
$('#tableId').DataTable.render.date(data, type, row, meta)... but this yielded a not a function error...
So is there a way at the point in my function that I determine the cell will hold a date, to just return the result of that render.date() helper?
Answers
Hi,
The way the date / time renderer works is to return a function, so you could do something like:
Where the arguments for
DataTable.render.date()
are the same as in the documentation for it anddata
being the value you want to render.More generally, the renderers are allowed to return objects as well as functions. We have a utility method internally to handle that sort of thing, and I'm wondering if we should expose it to make use of the renderers externally easier...
Allan
For what its worth the current version of DataTables that I have requires the following format:
Using only
DataTable.render.number()
returns an object, which is rather handy if you want to use the same format multiple times but does not actually render a value and causes an error if doneDataTable.render.date( from, to, locale, def )( data );
.