:: Home >>

Empty cells break sorting

Sorting is broken when you have empty cells or mix of numbers and strings in one column (JavaScript array data source).


The grid control assumes data is pre-formatted for display. This is done for performance reasons as formatting data on the server side is (typically) faster. So the grid displays data without any transformations but has to convert display text to numeric values during sorting.

The default text-to-value conversion is based on the value itself, not the whole column, so when the column contains mixed values - it breaks.


You have to specify the precise text-to-value conversion function for each column separately.

// prepare text-to-value conversion functions
function string(text){return text};
function number1(text){return Number(text)};
function number2(text){return Number(text.replace(/,/g, ""))};

// arrange them into array according to column types
var toValue = [string, string, number2, number2, number1];

// set data value to converted text
obj.setDataProperty("value", function(i,j){
    return toValue[j](myData[i][j]);

The code above fixes sorting for basic.htm data arrays. Here is the complete code:


9 Oct 06
Empy cell break / multipage grid Rekcor (0)
27 Jan 06
sorting still doesn't work (0)
18 Jan 06
Serious sorting BUG but should be easy to fix Dyme (9)
18 Oct 05
Not working... Pete (0)
14 Oct 05
Empty Cell Bug John Souv (3)
16 Sep 05
[no subject] Bruce Y (4)
14 Apr 05
Blank dates come up as #ERR ?? Matt (7)

Comments will appear on this page and in the main forum.


Recent changes:

2.5.0 - 2.5.6
2.5.0 - 2.5.5