sorting numerically with text in front of the number

sorting numerically with text in front of the number

sjwsjw Posts: 24Questions: 6Answers: 0

Hello I am trying to sort a column based on a room number in this format 'room no 151'. Currently it is not sorting correctly. If I sort descending it sorts room numbers based on the first number even if it is a 3 digit number ex:
Room no. 2
Room no. 1
Room no. 151
Is there a way to parse the number after the text?
thanks

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    You need to have DT render the field one way for display and another way for sorting.

    https://datatables.net/reference/option/columns.render

  • sjwsjw Posts: 24Questions: 6Answers: 0

    Hi Thom I don't see any of the examples in the link you presented sorting on a text + number string? I am unsure as to how it would work.

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    you will need to write a function that returns just the number for the sorting rendering.

This discussion has been closed.