Improper sorting with custom renderer and data-sort

Improper sorting with custom renderer and data-sort

yetyet Posts: 40Questions: 15Answers: 1

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

  • colincolin Posts: 4,624Questions: 0Answers: 814

    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

  • yetyet Posts: 40Questions: 15Answers: 1

    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?!

  • colincolin Posts: 4,624Questions: 0Answers: 814

    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

  • yetyet Posts: 40Questions: 15Answers: 1

    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

  • allanallan Posts: 49,474Questions: 1Answers: 7,275 Site admin

    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 and sort data types.

    Here is an update to show your example working: http://live.datatables.net/vixocaqe/2/edit .

    Allan

  • yetyet Posts: 40Questions: 15Answers: 1

    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

  • allanallan Posts: 49,474Questions: 1Answers: 7,275 Site admin

    I am clearly using the data-renderer="iso_8601" in production code for a while.

    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 render f: http://live.datatables.net/zotenoqi/4/edit .

    Allan

Sign In or Register to comment.