我的技術貼的首發地址:http://atian25.javaeye.com/

          天豬部落閣 - (ExtJS && AS3 && Java)

          專注于ExtJS && AS3 && Java

          常用鏈接

          統計

          FLASH

          WORK

          友情鏈接

          最新評論

          [原創]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 });

          posted on 2009-07-01 10:20 天豬 閱讀(3056) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 高唐县| 富裕县| 苏尼特右旗| 阿荣旗| 固安县| 清镇市| 沁源县| 揭阳市| 宁南县| 长沙市| 凭祥市| 乐昌市| 信宜市| 浮山县| 东光县| 岳阳县| 四会市| 交城县| 平武县| 张家口市| 成都市| 闻喜县| 岳普湖县| 平舆县| 正定县| 东台市| 永兴县| 仲巴县| 秀山| 成安县| 赤城县| 稷山县| 武强县| 抚顺市| 武乡县| 卓尼县| 西宁市| 合江县| 华宁县| 临沂市| 藁城市|