ソースを参照

Fix #76: After refreshing table data, search no longer works.

zhixin 11 年 前
コミット
8ab669e0c1
1 ファイル変更10 行追加6 行削除
  1. 10 6
      src/bootstrap-table.js

+ 10 - 6
src/bootstrap-table.js

@@ -511,16 +511,21 @@
     };
 
     BootstrapTable.prototype.onSearch = function (event) {
-        var that = this,
-            text = $.trim($(event.currentTarget).val());
+        var text = $.trim($(event.currentTarget).val());
 
         if (text === this.searchText) {
             return;
         }
         this.searchText = text;
 
-        if (this.options.sidePagination !== 'server') {
-            var s = that.searchText.toLowerCase();
+        this.options.pageNumber = 1;
+        this.initSearch();
+        this.updatePagination();
+    };
+
+    BootstrapTable.prototype.initSearch = function () {
+        if (this.searchText && this.options.sidePagination !== 'server') {
+            var s = this.searchText.toLowerCase();
 
             this.data = s ? $.grep(this.options.data, function (item) {
                 for (var key in item) {
@@ -533,8 +538,6 @@
                 return false;
             }) : this.options.data;
         }
-        this.options.pageNumber = 1;
-        this.updatePagination();
     };
 
     BootstrapTable.prototype.initPagination = function () {
@@ -1049,6 +1052,7 @@
 
     BootstrapTable.prototype.load = function (data) {
         this.initData(data);
+        this.initSearch();
         this.initPagination();
         this.initBody();
     };