分享

Extjs grid中文排序异常修正

 WindySky 2011-08-07
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);

        }

    }

};

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多