:: Forum >> Version 1 >>

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
Friday, November 21, 2003
Yes, another bug.
Alex (ActiveWidgets)
Friday, November 21, 2003
any fix for this? it still seems to be broken
eldiablo
Tuesday, August 24, 2004
Here is a fix:

obj.setDataProperty("value", function(i,j){
    var 
text "" this.getDataText(ij);
    if (
text.match(/^\s*$/)) {return ""}
    var 
value Number(text.replace(/[ ,%\$]/gi"").replace(/\((.*)\)/, "-$1"));
    return 
isNaN(value? text.toLowerCase() + " " value;
});

 
Alex (ActiveWidgets)
Tuesday, August 24, 2004

I have an alternate fix - patched grid.sort()

obj.sort = function(indexdirection){

  var 
model this.getModel("row");
  if (
model.sort) {
    return 
model.sort(indexdirection);
  }

  var 
= {};
  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;
    for (var 
i=0i<rows.lengthi++) {
      
a[rows[i]] = this.getDataProperty("value"rows[i], index);
    }
    
// @@@ main changes here
    // also optimized for descending sorting
    
rows.sort(function(x,y){return a[y] == "" || a[x] > a[y? 1 dir : (a[x] == a[y? 0 : -dir)});
  }

  
this.setRowProperty("values"rows);
  
this.setSortProperty("index"index);
  
this.setSortProperty("direction"direction);
};
 
Sudhaker Raj
Wednesday, August 25, 2004
obj.setDataProperty("value", function(i,j){
    var 
text "" this.getDataText(ij);
    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
Wednesday, August 25, 2004



This topic is archived.

Back to support forum

Forum search