EXTJS中文排序会出问题

学习EXTJS有一段时间了,遇到了两个问题,一个是点击列表栏该列进行排序,中文排序会出问题,需要在自己的程序中或者在extjs-all.js中添加代码:

Ext.data.Store.prototype.applySort = function() {
    if (this.sortInfo && !this.remoteSort) {
        var s = this.sortInfo, f = s.field;
        var st = this.fields.get(f).sortType;
        var fn = function(r1, r2) {
            var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
            if (typeof(v1) == "string") {
                return v1.localeCompare(v2);
            }
            return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
        };
        this.data.sort(s.direction, fn);
        if(this.snapshot && this.snapshot != this.data) {
            this.snapshot.sort(s.direction, fn);
        }
    }
};

另一个问题是ext默认label没有click事件,要想添加事件,同样在ext-all.js中添加一段代码即可:

Ext.form.Label.prototype.afterRender = Ext.form.Label.prototype.afterRender
     .createSequence(function() {
        this.relayEvents(this.el, ['click']);
       });





[转]Extjs 中文排序
已有 313 次阅读  2009-11-09 21:54


// 重载 Ext.data.Store.prototype.applySort 函数以修复 DataStore 对汉字排序异常的问题   
  
// var _applySort = Ext.data.Store.prototype.applySort;           
  
//如有需要,保存原 applySort 函数的引用   
  
             Ext.data.Store.prototype.applySort = function(){        //重载 applySort   
  
                                if(this.sortInfo && !this.remoteSort){   
  
                                        var s = this.sortInfo, f = s.field;   
  
                                        var st = this.fields.get(f).sortType;   
  
                                        var fn = function(r1, r2){   
  
                                                var v1 = st(r1.data[f]), v2 = st(r2.data[f]);   
  
                                                // 添加:修复汉字排序异常的Bug   
  
                                                if(typeof(v1) == "string"){ //若为字符串,  
 
                            //则用 localeCompare 比较汉字字符串, Firefox 与IE 均支持    
                             return v1.localeCompare(v2);
 
                         }   
  
                                                // 添加结束   
  
                       return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);   
  
                                         };   
  
                                        this.data.sort(s.direction, fn);   
  
                                        if(this.snapshot && this.snapshot != this.data){   
  
                                                this.snapshot.sort(s.direction, fn);   
  
                                         }   
  
                                 }   
  
                         };

你可能感兴趣的:(ext,prototype,IE,F#,firefox)