ExtJS Grid 自定义排序规则

有一些需求如:

1.一个文件管理的Grid,要求排序的时候,文件夹永远在顶部

2.一个显示成功率的Grid,要求成功数+失败数=0的数据,不参与排序,永远在底部

ExtJs本身并没有暴露这个接口,所以我们只能自己重写,如下代码:

 1  var store =  new Ext.data.JsonStore({  
 2   root:'data',  
 3   fields:[  
 4     'name',  
 5     {name:'sucCount',type:' int'},  
 6     {name:'failCount',type:' int'},  
 7     {name:'sucRate',type:' float'},  
 8     {name:'isValidateTest',type:' boolean'},  
 9     {name:'statType',type:' int'},  
10     'testLogIds','bsc','msc','sgsn'  
11   ],  
12   sortInfo:{field: 'sucRate', direction: 'ASC'},  
13    // 排序规则  
14   sortData: function(f, direction){  
15     direction = direction || 'ASC';  
16      var dir = direction == 'ASC' ? 1 : -1;  
17      var st =  this.fields.get(f).sortType;  
18      // 关键地方,重写排序排序规则  
19      var fn =  function(r1, r2){  
20        if(!r1.get('isValidateTest')||!r2.get('isValidateTest')){  
21          // 无效数据永远在下面  
22          return !r1.get('isValidateTest') ? dir : -dir;  
23       } else{  
24          var v1 = st(r1.data[f]), v2 = st(r2.data[f]);  
25          return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);  
26       }  
27     };  
28      this.data.sort(direction, fn);  
29      if( this.snapshot &&  this.snapshot !=  this.data){  
30        this.snapshot.sort(direction, fn);  
31     }  
32   }  
33 }); 

转载于:https://my.oschina.net/softwarechina/blog/180836

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值