Extjs Gird支持中文拼音排序实现代码

Extjs Gird支持中文拼音排序实现代码:
本文为大家详细介绍下Extjs Gird 支持中文拼音排序以及修复汉字排序异常的Bug、localeCompare比较汉字字符串,Firefox与IE均支持,感兴趣的朋友可以参考下,代码如下:

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"){//若为字符串 
      return v1.localeCompare(v2);//则localeCompare比较汉字字符串,Firefox与IE均支持 
    }//添加结束 
    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); 
  } 
} 
}; 
</script>

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=8176

更多内容可以参阅:http://www.softwhy.com/javascript/

你可能感兴趣的:(Extjs Gird支持中文拼音排序实现代码)