Sorting problem in Nulls

Sorting problem in Nulls

David123David123 Posts: 11Questions: 0Answers: 0
edited August 2013 in General
For string sorting, If sorting alphabetically it should put the blanks at the bottom. And reverse alphabetically blanks at the top.

Is it possible in following custom sorting? Please correct this following custom sorting?

jQuery.fn.dataTableExt.oSort['mystring-asc'] = function(x,y) {
if (x==y) return 0;
if (x == "") return -1;
if (y == "") return 1;
if (x > y) return 1;
}
jQuery.fn.dataTableExt.oSort['mystring-desc'] = function(y,x) {
if (x==y) return 0;
if (x == "") return -1;
if (y == "") return 1;
if (x > y) return 1;
}

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Absolutely it is possible - you can define a custom sort as you have done which will do what you need. Or you could override the default string sort to replace the default `string` function if you want to alter the default behaviour.

    Allan
  • David123David123 Posts: 11Questions: 0Answers: 0
    thanks allan.. But I have tried in Custom sorting for my below requirement..

    My expected output is:

    When sorting alphabetically or reverse alphabetically by Rendering engine columnn, it puts it in a random order

    If sorting alphabetically it should put the "."(dot) at the bottom. And reverse alphabetically "."(dot) at the top.

    But i didn't get the answer.

    I have posted a test case on http://live.datatables.net/iqadal/36/edit#javascript,live

    Please help to get this answer. I have tried so many hours but i didn't get the answer
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think the logic is a little confused. Try simplifying it like this: http://live.datatables.net/iqadal/37/edit

    Allan
  • David123David123 Posts: 11Questions: 0Answers: 0
    Thanks Allan. Great. but I found another one issue in that above http://live.datatables.net/iqadal/37/edit.

    sorting is working fine but it puts it in a random order when ascending or decending(except '.'). Its not sorting properly in all data.

    When decending:(Issue)

    EED
    ERD
    GEC
    RED
    RED
    TRD
    TRE
    WEB
    cre
    her
    jish
    jos
    ked
    .
    .
    .
    .
    .

    In above result ,when ascending uppercase datas are sorted first then lower case datas have sorted next.Its wrong.

    Its sorting in both uppercase and lowercase properly. Is it possible to correct this issue?
This discussion has been closed.