ext grid 对IP地址自定义排序

         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]);
                         //alert(v1+'--'+v2);
                         var  re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g  //匹配IP地址的正则表达式
                         if (re.test(v1)){
                             var  a1 = parseInt(RegExp.$1);
                             var  a2 = parseInt(RegExp.$2);
                             var  a3 = parseInt(RegExp.$3);
                             var  a4 = parseInt(RegExp.$4);
                             var  re2=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/g  //匹配IP地址的正则表达式
                             re2.test(v2)
                             var  b1 = parseInt(RegExp.$1);
                             var  b2 = parseInt(RegExp.$2);
                             var  b3 = parseInt(RegExp.$3);
                             var  b4 = parseInt(RegExp.$4);
                             //alert('i1:'+i1+';i2:'+i2);
                             if (a1 != b1){
                                 return  a1 > b1 ? 1 : -1;
                             }
                             if (a2 != b2){
                                 return  a2 > b2 ? 1 : -1;
                             }
                             if (a3 != b3){
                                 return  a3 > b3 ? 1 : -1;
                             }
                             if (a4 != b4){
                                 return  a4 > b4 ? 1 : -1;
                             }
                             return  0;
                         }
                            
                         if ( typeof (v1) ==  "string" ){ 
                             return  v1.localeCompare(v2);  
                         }
                         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);
                 }
         }
     };
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值