If I have a column with values like this
a
e
null
null
b
f
And toggle sort on that column, only the values above null are affected
e
a
null
null
b
f
Can null values be read as empty strings/ or some value that places them on the bottom when sorting
Can the sort function be replaced with a custom sort function?
a
e
null
null
b
f
And toggle sort on that column, only the values above null are affected
e
a
null
null
b
f
Can null values be read as empty strings/ or some value that places them on the bottom when sorting
Can the sort function be replaced with a custom sort function?
8 Answers, 1 is accepted
0

Guido
Top achievements
Rank 1
answered on 27 Jun 2012, 07:04 PM
I hate having to edit the source, but this is my solution for now. I've edited the asc and desc functions in var Comparer. I've added null checks.
asc:
function
(field) {
var
selector =
this
.selector(field);
return
function
(a, b) {
a = selector(a);
b = selector(b);
if
(a ===
null
) {
if
(b ===
null
) {
return
0;
}
return
1;
}
if
(b ===
null
) {
return
-1;
}
return
a > b ? 1 : (a < b ? -1 : 0);
};
},
desc:
function
(field) {
var
selector =
this
.selector(field);
return
function
(a, b) {
a = selector(a);
b = selector(b);
if
(a ===
null
) {
if
(b ===
null
) {
return
0;
}
return
-1;
}
if
(b ===
null
) {
return
1;
}
return
a < b ? 1 : (a > b ? -1 : 0);
};
},
0

Erlend
Top achievements
Rank 2
answered on 19 Sep 2012, 01:49 PM
Is there no other way, than edit source?
This should be last resort, as this will create issues on upgrades and using minified versions.
Telerik Support Staff!, are you able to give a better guidance here?
Thanks
This should be last resort, as this will create issues on upgrades and using minified versions.
Telerik Support Staff!, are you able to give a better guidance here?
Thanks
0

Joel
Top achievements
Rank 1
answered on 13 Jan 2015, 01:22 AM
This is a very important feature. Is there still a solution to this that doesn't require editing the source?
0
Hello Joel,
It works correctly with the latest version. Please see the example below:
Or am I missing something?
Regards,Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Joel
Top achievements
Rank 1
answered on 15 Jan 2015, 05:31 PM
No, that's not working correctly because the null value was able to reach the top of the sort.
0

Joel
Top achievements
Rank 1
answered on 15 Jan 2015, 05:33 PM
The behavior that is wanted in this case is to group all null/empty values at the bottom of the sort, no matter if it's sorting in ascending or descending. Null values should always be at the bottom since they do not contribute anything in an ascending sort.
0

Joel
Top achievements
Rank 1
answered on 15 Jan 2015, 05:41 PM
Here is a wonderful example: http://jsfiddle.net/CYubV/
0
Hello Joel,
If you are not happy with the current sorting algorithm you can declare your own custom sorter, and handle your scenario. Here is some documentation and example that might help:
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.sortable.compare
Regards,
Kiril Nikolov
Telerik
If you are not happy with the current sorting algorithm you can declare your own custom sorter, and handle your scenario. Here is some documentation and example that might help:
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-columns.sortable.compare
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!