Natural Sorting Plugin - Sorting Without Default Column?

Natural Sorting Plugin - Sorting Without Default Column?

JoyrexJoyrex Posts: 92Questions: 14Answers: 3

I am using the Natural Sorting plugin, and I have found that unless I provide a default column to sort by, the plugin won't be invoked until a header column is clicked on. A snippet from my columnDefs:

},{
 targets: 2,
 width: "100%",
 type: 'natural-ci'
} ],
order: [[2,'asc']] //normally this is an empty array as I don't want a default sort by a particular column

Is that the expected behavior?

Also, I tried using 'natural-ci-asc' and it does not work, even though it is in the plugin code. Is there anywhere all the sorting types are defined correctly?

Any help is appreciated!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918
    edited June 2019

    Thats the way Datatables works. It will only sort by a column if you click the header, use order or order() to order by that column. If you use order: [] then Datatbles won't order by any column. The rows will be displayed in the order they are received/processed. If you don't want an initial table order then you could have your server script return the data in the order you initially want, by column 2 for example.

    Please provide details about what you are trying to achieve. Maybe we can help with a solution.

    Kevin

  • JoyrexJoyrex Posts: 92Questions: 14Answers: 3

    Kevin,

    Thanks for the response - I guess what I was expecting was the Natural Sorting plugin to order the contents of the column it is applied to, but not necessarily apply a sort order to the entire table, if that makes sense.

    I don't have my server-side script returning the data in any particular order since MSSQL doesn't do ordering "naturally" (AFAIK) like the plugin does, and my hope was the Natural Sorting plugin would keep numbered directories without leading zeros ordered correctly (that old chestnut of having 1 followed by 10 then 2...).

  • kthorngrenkthorngren Posts: 21,147Questions: 26Answers: 4,918
    Answer ✓

    When using a sorting plugin you configure the columns.type for the desired columns. Basically changing it from what Datatables would normally set the type to, like 'num' or 'text'. Whether a plugin is used or not Datatables isn't going to change the order of the table unless specified.

    If you want the initial table ordered by that column then you would need to use order: [[2,'asc']]. If you want the table always ordered by that column you could use orderFixed or maybe something like columns.orderData will achieve what you want.

    Kevin

This discussion has been closed.