Natural Sorting Plugin - Sorting Without Default Column?
Natural Sorting Plugin - Sorting Without Default Column?

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
This discussion has been closed.
Answers
Thats the way Datatables works. It will only sort by a column if you click the header, use
order
ororder()
to order by that column. If you useorder: []
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
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...).
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 useorderFixed
or maybe something likecolumns.orderData
will achieve what you want.Kevin