我的技術(shù)貼的首發(fā)地址:http://atian25.javaeye.com/

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

          專注于ExtJS && AS3 && Java

          常用鏈接

          統(tǒng)計(jì)

          FLASH

          WORK

          友情鏈接

          最新評(píng)論

          [原創(chuàng)]ExtJS Grid 自定義排序規(guī)則

          有一些需求如:

          1.一個(gè)文件管理的Grid,要求排序的時(shí)候,文件夾永遠(yuǎn)在頂部

          2.一個(gè)顯示成功率的Grid,要求成功數(shù)+失敗數(shù)=0的數(shù)據(jù),不參與排序,永遠(yuǎn)在底部

          ExtJs本身并沒(méi)有暴露這個(gè)接口,所以我們只能自己重寫,如下代碼:

           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   //排序規(guī)則  
          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     //關(guān)鍵地方,重寫排序排序規(guī)則  
          19     var fn = function(r1, r2){  
          20       if(!r1.get('isValidateTest')||!r2.get('isValidateTest')){  
          21         //無(wú)效數(shù)據(jù)永遠(yuǎn)在下面  
          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 天豬 閱讀(3057) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 泗水县| 库尔勒市| 湘西| 体育| 自治县| 岢岚县| 南丰县| 辉县市| 永城市| 杨浦区| 天气| 施甸县| 新津县| 浮梁县| 达日县| 吴川市| 赞皇县| 佛冈县| 台湾省| 邛崃市| 富川| 金湖县| 大竹县| 竹北市| 景德镇市| 塔河县| 田阳县| 定边县| 基隆市| 清河县| 柳林县| 同江市| 新乡市| 翁源县| 孝昌县| 涟源市| 监利县| 全南县| 克什克腾旗| 来凤县| 鸡西市|