ext gridpanel排序

x_fhsm 2012-08-30 03:53:08
ext的gridpanel点击列标题排序,怎么2比10还要大,还有日期的排序根本不对,求解决方法
...全文
144 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
月底了,请尽快结贴!
x_fhsm 2012-08-30
  • 打赏
  • 举报
回复
灰常感谢
未知数 2012-08-30
  • 打赏
  • 举报
回复
字符串的比较就是这个结果....
可以重写排序的算法:
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]);
var num1,num2;
if (typeof(v1) == "string") {
if(v1=='' && v2!='') return -1;
if(v1 !='' && v2=='') return 1;
if(v1=='' && v2=='') return 0;
num1=parseFloat(v1.replace(/-/g,''));
num2=parseFloat(v2.replace(/-/g,''));
if(isNaN(num1)) {num1=v1;}
if(isNaN(num2)) num2=v2;
}
else
return v1.localeCompare(v2);
//}
return num1 > num2 ? 1 : (num1 < num2 ? -1 : 0);
};
this.data.sort(s.direction, fn);
if(this.snapshot && this.snapshot != this.data) {
this.snapshot.sort(s.direction, fn);
}
}
};
把这段代码放到页面中就可以了,项2011-1,2011-1-1之类的日期写法都能排正确,数字也不会错

月底了,请尽快结贴

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧