Browse Source

Fix #38: search data error.

zhixin 11 years ago
parent
commit
29a1ab7040
2 changed files with 5 additions and 4 deletions
  1. 1 1
      docs/examples.html
  2. 4 3
      src/bootstrap-table.js

+ 1 - 1
docs/examples.html

@@ -527,7 +527,7 @@
                     <div class="alert alert-success" id="events-result">
                     <div class="alert alert-success" id="events-result">
                         Here is the result of event.
                         Here is the result of event.
                     </div>
                     </div>
-                    <table id="events-table" data-url="data1.json" data-height="246">
+                    <table id="events-table" data-url="data1.json" data-height="246" data-search="true">
                         <thead>
                         <thead>
                         <tr>
                         <tr>
                             <th data-field="state" data-checkbox="true"></th>
                             <th data-field="state" data-checkbox="true"></th>

+ 4 - 3
src/bootstrap-table.js

@@ -286,6 +286,7 @@
         } else {
         } else {
             this.data = data || this.options.data;
             this.data = data || this.options.data;
         }
         }
+        this.options.data = this.data;
 
 
         this.initSort();
         this.initSort();
     };
     };
@@ -418,7 +419,7 @@
         this.searchText = text;
         this.searchText = text;
 
 
         if (this.options.sidePagination !== 'server') {
         if (this.options.sidePagination !== 'server') {
-            this.searchData = $.grep(this.data, function (item) {
+            this.data = $.grep(this.options.data, function (item) {
                 for (var key in item) {
                 for (var key in item) {
                     if (typeof item[key] === 'string' && item[key].indexOf(that.searchText) !== -1) {
                     if (typeof item[key] === 'string' && item[key].indexOf(that.searchText) !== -1) {
                         return true;
                         return true;
@@ -444,7 +445,7 @@
             $first, $pre,
             $first, $pre,
             $next, $last,
             $next, $last,
             $number,
             $number,
-            data = this.searchText ? this.searchData : this.data;
+            data = this.searchText ? this.data : this.options.data;
 
 
         if (this.options.sidePagination !== 'server') {
         if (this.options.sidePagination !== 'server') {
             this.options.totalRows = data.length;
             this.options.totalRows = data.length;
@@ -604,7 +605,7 @@
     BootstrapTable.prototype.initBody = function () {
     BootstrapTable.prototype.initBody = function () {
         var that = this,
         var that = this,
             html = [],
             html = [],
-            data = this.searchText ? this.searchData : this.data;
+            data = this.searchText ? this.data : this.options.data;
 
 
         this.$body = this.$el.find('tbody');
         this.$body = this.$el.find('tbody');
         if (!this.$body.length) {
         if (!this.$body.length) {