Stable sort

Stable sort

Vilhelm PerssonVilhelm Persson Posts: 11Questions: 0Answers: 0
edited September 2010 in General
Is there some way to turn on stable sorting of the columns (sort on one column but in case of duplicate keep the position of previous sort)?
I know there is the multiple sort option by pressing Shift but this is not what I search for.

I have search the forum for this but since stable is in sTable and stable version it is herd to find.
According to DataTables v1.6 beta 1 the sort is stable but when I test for example the http://www.datatables.net/examples/basic_init/zero_config.html the sort is not stable.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Vilhelm,

    The sorting used by DataTables should be stable at the moment. Could you perhaps say what columns you need to sort, and in what order, to allow me to reproduce this - as it looks okay to me? When testing this originally I found that most browsers to do a stable sort, but Chrome and Opera do not. Also, which browser are you using?

    Thanks!
    Allan
  • Vilhelm PerssonVilhelm Persson Posts: 11Questions: 0Answers: 0
    Hi
    If I use the zero_config example on the datatables.net site and first do a sort on Browser A to Z and then Platform A-Z I see Embedded devices at top but the Browser is no longer sorted as the original since Dido comes after NetFront.
    I have IE 8.0.6001 and Firefox 3.6.9 (with Firebug) and get the same behavior in both.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Vilhelm,

    I do indeed see what you mean. Thanks for the heads up on this. I'm travelling at the moment, so I can't look into it too much, but I will do so and get back to you.

    Regards,
    Allan
  • Vilhelm PerssonVilhelm Persson Posts: 11Questions: 0Answers: 0
    Hi
    I noticed there where an new version out.
    I still have this problem when I test the zero_config example.
    A stable sort would be nice, but also if possible to add a flag if the sorting should be stable or not since I guess a stable sort will use a bit more computation.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Vilhelm,

    Unfortunately I didn't get a chance to look into this for the new release. For what did make it in, please see the release notes ( http://datatables.net/download ). I'll certainly have a look at this before 1.7.3 is released, although there might not be a change in for it in that release, it might need to wait for the next one, depending on what exactly needs to be done.

    Regards,
    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Vilhelm,

    I've been looking into this, and believe I understand what is happening now, and even better, I've got it fixed - thanks so much for spotting this and letting me know about it.

    If you are interested, basically the issue (which has actually been there since I introduced the "stable sort" originally) was that when the values being sorted match, and therefore stable sorting comes into play, it would do a numeric sort on the value of the index (not the position of that index, as it should have been). As such, the position of the rows when in this situation would be directly defined by their position in the original HTML table (i.e. since the 'Dillo' browser came after 'NetFront' in the HTML, it would come after in the sorted data).

    The fix is to make it sort on the position of the array value being sorted, rather than it's own value. All a bit convoluted, but I'm fairly happy that it is in fact now doing a stable sort. I've committed 12 unit tests to try an pick up any issues which might occur with this in future.

    I'll release this fix as part of 1.7.3, hopefully fairly soon.

    Thanks again!
    Allan
This discussion has been closed.