Need help with sorting

Need help with sorting

Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

I need assistance sorting the first column. I have a column with a mix of alpha numeric values. Is it possible for the column to ignore the alpha values and only sort by numeric values?

See test case: http://live.datatables.net/peyinuhi/2/edit

In my table, for example, AA-EC-1991-175 and AA-MW-1991-136 should ignore alpha values and sort by 1991-175 and 1991-136. As a result, the expected outcome should be:

AA-MW-1991-136 test5 test5 test5 (first)
AA-EC-1991-175 test1 5 16

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Yes that is possible, but you'll need a custom ordering plug-in to do it. Strip the non-numeric data and then parse the numeric data into something that can be sorted - e.g. in this case "YYYY0BBB" might work (where YYYY is 1991 and BBB is the 136 part).

    Allan

  • Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

    Thanks Allan. I am not a developer. I am not sure how to proceed with what you mentioned. Can you please guide me. Thanks

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited October 2022 Answer ✓

    The first thing to do is to extract the text from the p tag. Then parse the string to get to get the two numeric values. Pad the last number with 0s to make them all the same length. The place the 0 between the two numbers as Allan suggested.

    Using Orthogonal data you can return this new string for the -type (type detection) and sort operations. For example AA-EC-1991-190 would be 19910190 and AA-EC-2011-50 would be 20110050. I changed a couple of the data points to AA-WE-2010-30 and AA-MW-2010-101 to illustrate the sorting of the variable length digits for the last part. See this example:
    http://live.datatables.net/peyinuhi/4/edit

    Kevin

  • Noodles12Noodles12 Posts: 113Questions: 41Answers: 2

    Thankyou very much!. This worked!!

Sign In or Register to comment.