String sorting bug
To reproduce:
Edit examples/basic.htm and change "Intuit Inc." in the data to an empty string, "". Then launch basic.htm and try sorting by Company Name.
When there's an empty string within the rows of a column, it stays somewhere in the middle when sorted.
Ates Goral
November 21,
any fix for this? it still seems to be broken
eldiablo
August 24,
Here is a fix:
obj.setDataProperty("value", function(i,j){
var text = "" + this.getDataText(i, j);
if (text.match(/^\s*$/)) {return ""}
var value = Number(text.replace(/[ ,%\$]/gi, "").replace(/\((.*)\)/, "-$1"));
return isNaN(value) ? text.toLowerCase() + " " : value;
});
Alex (ActiveWidgets)
August 24,
I have an alternate fix - patched grid.sort()
obj.sort = function(index, direction){
var model = this.getModel("row");
if (model.sort) {
return model.sort(index, direction);
}
var a = {};
var rows = this.getRowProperty("values");
if (direction && direction != "ascending" ) {
direction = "descending";
}
else {
direction = "ascending";
}
if (this.getSortProperty("index") != index || this.getSortProperty("direction") != direction) {
var dir = (direction == "descending") ? -1 : 1;
for (var i=0; i<rows.length; i++) {
a[rows[i]] = this.getDataProperty("value", rows[i], index);
}
rows.sort(function(x,y){return a[y] == "" || a[x] > a[y] ? 1 * dir : (a[x] == a[y] ? 0 : -1 * dir)});
}
this.setRowProperty("values", rows);
this.setSortProperty("index", index);
this.setSortProperty("direction", direction);
};
Sudhaker Raj
August 25,
obj.setDataProperty("value", function(i,j){
var text = "" + this.getDataText(i, j);
if (text.match(/^\s*$/)) {return "!"}
var value = Number(text.replace(/[ ,%\$]/gi, "").replace(/\((.*)\)/, "-$1"));
return isNaN(value) ? text.toLowerCase() + " " : value;
});
almost worked for me, note returning "!" was needed to get the thing to work right - bizarro especially as the solution worked as given on the basic.html grid.
eldiablo
August 25,