:: Documentation >>

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).

Background

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.

Solution

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:

Comments

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

Documentation:

Recent changes:

2.6.4
2.6.3
2.6.2
2.6.1
2.6.1
2.6.0
2.5.0 - 2.5.6
2.5.6
2.5.0 - 2.5.5
2.5.5