EXT 中文排序问题

  1. // 重载 Ext.data.Store.prototype.applySort 函数以修复 DataStore 对汉字排序异常的问题   
  2.   
  3. // var _applySort = Ext.data.Store.prototype.applySort;           
  4.   
  5. //如有需要,保存原 applySort 函数的引用   
  6.   
  7.             Ext.data.Store.prototype.applySort = function(){        //重载 applySort   
  8.   
  9.                                 if(this.sortInfo && !this.remoteSort){    //sortInfo对象存在并且不是远程排序
  10.   
  11.                                         var s = this.sortInfo, f = s.field;   
  12.   
  13.                                         var st = this.fields.get(f).sortType;   
  14.   
  15.                                         var fn = function(r1, r2){   
  16.   
  17.                                                 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);   
  18.   
  19.                                                 // 添加:修复汉字排序异常的Bug   
  20.   
  21.                                                 if(typeof(v1) == "string"){ //若为字符串类型,   
  22.                                                   //则用 localeCompare 比较汉字字符串, Firefox 与 IE 均支持
  23.                                                        return v1.localeCompare(v2);
  24.                                                  }   
  25.   
  26.                                                 //若不是字符串类型  
  27.                                                 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);   
  28.   
  29.                                         };   
  30.   
  31.                                         this.data.sort(s.direction, fn);   
  32.   
  33.                                         if(this.snapshot && this.snapshot != this.data){   //数据快照
  34.   
  35.                                                 this.snapshot.sort(s.direction, fn);   
  36.   
  37.                                         }   
  38.   
  39.                                 }   
  40.   
  41.                         };  

你可能感兴趣的:(function,String,ext,IE,firefox)