How can I sort words in a particular order?

How can I sort words in a particular order?

rotaerczrotaercz Posts: 31Questions: 7Answers: 0

Say I have a column that will be populated with the following words:

Legendary, Rare, Uncommon, Common

I can't sort this alphabetically because the sorting would be wrong. How can I sort this in the above respective order?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,945

    Probably what I would do is use Orthogonal Data and assign a numeric value to each word for the sort operation.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Yep, as Kevin, said that's the way to go - see here.

    C

  • rotaerczrotaercz Posts: 31Questions: 7Answers: 0

    Thank you!

  • rotaerczrotaercz Posts: 31Questions: 7Answers: 0
    edited July 2018

    This was working well but after I made it a button it sorts alphabetically again. Is there a way to ignore the <a></a> html?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    You can just fiddle with that string within the render function in the same way, it will just need to look inside the element

  • rotaerczrotaercz Posts: 31Questions: 7Answers: 0

    The data variable is empty when I create the rows with <a></a> html but when I create the rows without the extra html I can see the string.

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,945
    Answer ✓

    How are you creating the rows?

    Maybe you can provide a test case so we can help.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • rotaerczrotaercz Posts: 31Questions: 7Answers: 0

    Oh never mind! Actually, the problem was because when initializing I had a 'columns' and a 'columnDefs' after it. I removed the columnDef and just added the render code you provided to columns and I'm getting the string! Thanks for helping me. I appreciate it. :)

This discussion has been closed.