Limit number of columns in multi-column sorts
Limit number of columns in multi-column sorts
Hey Allan,
We recently implemented several of the new features in DataTables 1.10.x and our users love the additions. In particular, some users really love the multi-column sorts (old Excel habits die hard, ha). However, the backend we use for our DataTables ( Sphinx, http://sphinxsearch.com/about/sphinx/ ) has a known issue with a hard limit of 5 sort bys ( http://sphinxsearch.com/bugs/view.php?id=1992 ). Is there any way to set a max number of columns allowed in a compound sort?
Thanks,
-steve
This question has an accepted answers - jump to answer
Answers
Hey Allan,
Any thoughts on this?
Thanks,
-steve
Hi Steve,
Currently no, I'm afraid there is no way to set a limit on the number of compound sort elements that DataTables can perform. To be honest, that isn't a limitation that exists in the DataTables core Javascript, nor in the other server-side platforms I've worked with, so this is the first time I've come across this.
One possible workaround at the moment might be to throw away the compound sort elements >5. You could do that using the
ajax.data
option on the client-side and truncating theorder
array, or performing a similar action at the server-side. It wouldn't stop the users being able to select 6 or more columns for the sort, but it would stop any errors that are emitted by the server-side from making the table unusable (if that is currently happening).Another option might be to listen for the
order
event and if it is found to contain too many elements in the array, truncate and then redraw the table again - the downside to this method is that it is inefficient and it will result in the table being in the invalid state momentarily.The only other option is to modify DataTables core to disallow additional elements. I'd rather not put that option into the core since this is a bug in third party software, and not DataTables.
Regards,
Allan