Custom sorting: -asc/-desc not called when -pre is present
Custom sorting: -asc/-desc not called when -pre is present
ralphje
Posts: 2Questions: 0Answers: 0
There seems to be an issue with DT 1.10. When a custom sorting method is built with all three sorting-pre, -asc and -desc methods, -asc and -desc are not called anymore. Only the pre-function is called. Moreover, when -pre is not present, -asc and -desc ARE called.
See this fiddle: http://jsfiddle.net/H5cjN/1/
This discussion has been closed.
Replies
That's not an "issue", that's a feature! The
-pre
function is used as an optimisation - it calculated the data to be sorted, so it is only ever called once for every cell. Then the built in sorter can simply sort the data without needing to call external functions - a two fold optimisation.If you do want the
-asc
and-desc
functions to be called, don't provide-pre
.Allan
I doubt this constitutes as a feature, as the following can be found in the source of DT 1.10:
Additionally, many plug-ins at http://datatables.net/plug-ins/sorting/ seem to implement all three functions, adding to the confusion.
Finally, my use case requires both a pre method and asc and desc methods, requiring me now to implement the pre method in a separate function, calling it on the two parameters passed to the asc and desc methods and thus making my code sanitize some of the input values multiple times.
The comment is wrong. i'll update it. That comes from 1.9 when that was true.
They do, for 1.9 compatibility only. If you look at the
-desc
and-asc
parts of those plug-ins you will see that they are all trivial sorts, proving that there is no need for them.That's fine. Do as you say and simply have an external function that you call. A number of the other plug-ins (natural sorting for example) also do that.
Alternatively, you are of course welcome to modify DataTables to suit your need - it is open source after all :-)
Allan
Actually - I just grepped the code and can't find the comment you mention anywhere in the source as you say. Can you point me to where it is so I can correct it?
Allan