How to segregate different types in the same column when sorting

How to segregate different types in the same column when sorting

trechubettrechubet Posts: 4Questions: 2Answers: 0

Link to test case:

Description of problem:

I have a table column that can contain either numbers or img tags. I want to:

  • Segregate the numeric values from the "other" values
  • Always keep all images below the group of sorted numbers at the top
  • Sort only the numeric values according to ASC or DESC

How can I implement this with DataTables?

Reproducing the Issue:

  • Visit the Test Case
  • Sort the On Hand column into Descending order
    • Notice that the image rows are in between the number rows
  • Sort the On Hand column into Ascending order
    • Notice that the sorting appears correct, but the numbers are at the bottom (last page)

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 22,261Questions: 26Answers: 5,122
    Answer ✓

    TYour test case has some errors in the console and doesn't run properly. To sort a mix of data you will need to create a sorting plugin. When there is a mix of data types Datatables type detection sets those columns to text which can result sorting that is not desired.

    You can look at the sorting plugins page to see if any will work for your data. This plugin may do what you want. If not maybe you can refactor it to work for your environment.

    Kevin.

Sign In or Register to comment.