浏览代码

Improving the performance of the search in filter control extension

Dennis Hernández 8 年之前
父节点
当前提交
5ddff518df
共有 1 个文件被更改,包括 20 次插入21 次删除
  1. 20 21
      src/extensions/filter-control/bootstrap-table-filter-control.js

+ 20 - 21
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -586,10 +586,10 @@
         }
 
         var that = this;
-        var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
+        var fp = $.isEmptyObject(that.filterColumnsPartial) ? null : that.filterColumnsPartial;
 
         //Check partial column filter
-        this.data = fp ? $.grep(this.data, function (item, i) {
+        that.data = fp ? $.grep(that.data, function (item, i) {
             for (var key in fp) {
                 var thisColumn = that.columns[that.fieldsColumnsIndex[key]];
                 var fval = fp[key].toLowerCase();
@@ -602,28 +602,27 @@
                     [value, item, i], value);
                 }
 
-                if (thisColumn.filterStrictSearch) {
-                    if (!($.inArray(key, that.header.fields) !== -1 &&
-                        (typeof value === 'string' || typeof value === 'number') &&
-                        value.toString().toLowerCase() === fval.toString().toLowerCase())) {
-                        return false;
-                    }
-                } else if (thisColumn.filterStartsWithSearch) {
-                  if (!($.inArray(key, that.header.fields) !== -1 &&
-                      (typeof value === 'string' || typeof value === 'number') &&
-                      (value + '').toLowerCase().indexOf(fval) === 0)) {
-                      return false;
-                  }
-                } else {
-                    if (!($.inArray(key, that.header.fields) !== -1 &&
-                        (typeof value === 'string' || typeof value === 'number') &&
-                        (value + '').toLowerCase().indexOf(fval) !== -1)) {
-                        return false;
+                if($.inArray(key, that.header.fields) !== -1 ) {
+                    if(typeof value === 'string' || typeof value === 'number') {
+                        if (thisColumn.filterStrictSearch) {
+                            if(value.toString().toLowerCase() === fval.toString().toLowerCase()) {
+                                return true;
+                            }
+                        } else if (thisColumn.filterStartsWithSearch) {
+                            if((value + '').toLowerCase().indexOf(fval) === 0) {
+                                return true;
+                            }
+                        } else {
+                            if((value + '').toLowerCase().indexOf(fval) !== -1) {
+                                return true;
+                            }
+                        }
                     }
                 }
             }
-            return true;
-        }) : this.data;
+
+            return false;
+        }) : that.data;
     };
 
     BootstrapTable.prototype.initColumnSearch = function(filterColumnsDefaults) {