Sort table by priority list of strings
Sort table by priority list of strings
parsonsparsons19
Posts: 3Questions: 1Answers: 0
First of all happy holidays to everyone.
I have a table where one of the columns will have values of "level 1", "level 2", "level 3", "unlisted", "suppressed", etc. I want to sort this table by the order stated above but I am not seeing a way to do it. I looked into the enum.js plug in but I wasn't able to figure out how to apply the order based on the example they give.
Any help would be greatly appreciated, thank you!
Answers
The enum plug-in is exactly the way to do it (assuming you are using client-side processing).
This blog post describes that plug-in and how to use it. If you have any problems with it, let me know (and link to a test case showing the problem please).
Allan
Awesome thank you I will take a look.
Edit #2: I copied the script in the blog post to the following:
$.fn.dataTable.enum(["Level 1", "Level 2", "Level 3", "Unlisted", "Suppressed", ""]);
$("#column-variants").DataTable();
I get the error $.fn.dataTable.enum is not a function
Edit #1: Ok so I read it but the post is confusing because I am not sure where I am supposed to be putting my enum values. This doesn't seem to be working for me:
$("#column-variants").DataTable({
"language": {
"search": "Search all columns:"
},
enum: ["Level 1", "Level 2", "Level 3", "Unlisted", "Surpressed", ""],.....
Suggests that the plugin hasn't been loaded. Can you link to the page showing the issue please? Are you using script tags, or npm? Perhaps you can show me your full code?
Allan
I definitely think there is something up with the order of my script execution so I will check that out.
Load order should be:
With npm / bundlers it might be a little more difficult, but it will still be doable.
Allan