MultiColumn Ordering - LImit to only 2 columns at a time
MultiColumn Ordering - LImit to only 2 columns at a time
smoldovanskiy
Posts: 62Questions: 8Answers: 0
in DataTables
Is there a way to limit the multi column ordering to only 2 columns at a time? On the client side, I want to allow users to sort up to 2 columns at a time.
This question has accepted answers - jump to:
Answers
There's no restriction - it's enable all sorting, or have none at all - so I can't think of a way to enforce that, I'm afraid,
Colin
I would love this as an enhancement, a setting to specify max number of sort columns
Hi,
It is a somewhat cheeky way to do it, but you can use a listener on the
draw
event and then use the API to check the current ordering. If there are more than 2 columns, then stop it from doing that:http://live.datatables.net/buhuhari/1/edit
It isn't quite right, since it does involve an extra draw which might cause a problem if server-side processing is being used?
preDraw
might be useful for that.Can I ask, what is the use case for this? I don't think we've been asked for this feature before.
Regards,
Allan
It is server side so with each extra layer of sorting code logic becomes more complicated.
I want it limited to just the two columns as per user requirement, they need to sort by date and then by and index number.
If you want to limit sorting to two specific columns you can use
columns.orderable
.Kevin
I want them all to be orderable, but I need to limit the ordering to two columns at a time or less.
You could pre-process the
order
array in your server-side processing script and just remove the items in the array after index 1. The UI wouldn’t quite be right, since it would still show the sorting arrows as active on the third, fourth, nth, columns - but it wouldn’t sort.Unfortunately, what you are looking for is not a built in feature of DataTables.
Allan