Improper sorting with custom renderer and data-sort
Improper sorting with custom renderer and data-sort
Using DT 1.10.15 with an HTML table containing all data in cells and all other configurations as data attributes.
On column 'modified' is used to render dates.
The related col header contains a data-renderer="iso_8601" that converts a cell with an ISO8601 data into DD.MM.YYYY.
The cell looks like this
<td data-order="2019-10-12T00:12:123">
2019-10-12T00:12:123
</td>
The cell renders as '12.10.2019' using the custom renderer.
How clicking on the header of the column sorts the data by the rendered string and not as configured by the value of the data-order attribute.
Bug or Feature?
Answers
Hi @yet ,
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I tried to setup a minimal example here:
http://live.datatables.net/vixocaqe/1/edit
but the configured renderer "render_iso8601" is not used by the demo?!
Hi @yet ,
It would be helpful if that demo demonstrated the problem, with steps on how to reproduce, and what you would expect.
Cheers,
Colin
I am clearly trying to setup a demo according to our problem but as indicated: the data-renderer functionality does not work on the live.datatables.net
Using the
data-renderer
attribute as a function name shouldn't actually work anywhere, not just on the live site. Have you got it working elsewhere?As the documentation for
columns.renderer
notes, if you use a string value (which is the case here) DataTables will attempt to access a property by that name in the row's object data source.Also in your rendering function you need to take account of the different request types - e.g. return the data you want to sort on for the
type
andsort
data types.Here is an update to show your example working: http://live.datatables.net/vixocaqe/2/edit .
Allan
I am clearly using the data-renderer="iso_8601" in production code for a while.
The given example does not make sense.
Check this modified example where the renderer is supposed to return "foo" for each cell. But the cell content still displays the ISO date
http://live.datatables.net/zotenoqi/1/edit
Fair enough - that's not something that is documented or tested though. I wouldn't have expected it to work and it wasn't designed that way .
The
data-*
attributes in your HTML there are overriding the rendering function you are giving. Remove them and it does indeed renderf
: http://live.datatables.net/zotenoqi/4/edit .Allan