ext grid IP 주소 사용자 정의 정렬

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]);
                        //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); 
                } 
        }
    };

좋은 웹페이지 즐겨찾기