Browse Source

Merge pull request #2049 from fenichelar/develop

feat(filter-control extension): add select list data to be passed in as JSON string and filter control starts with search
wenzhixin 10 years ago
parent
commit
57d4eac593

+ 6 - 1
src/extensions/filter-control/README.md

@@ -40,7 +40,7 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 ### filterData
 
 * type: String
-* description: Set custom select filter values, use `var:variable` to load from a variable or `url:http://www.example.com/data.json` to load from json file. 
+* description: Set custom select filter values, use `var:variable` to load from a variable or `url:http://www.example.com/data.json` to load from a remote json file or `jso:{key:data}` to load from a json string. 
 * default: `undefined`
 
 ### filterDatepickerOptions
@@ -53,6 +53,11 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 * description: Set to true if you want to use the strict search mode.
 * default: `false`
 
+### filterStartsWithSearch
+* type: Boolean
+* description: Set to true if you want to use the starts with search mode.
+* default: `false`
+
 ### Icons
 * clear: 'glyphicon-trash icon-clear'
 

+ 15 - 1
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -272,6 +272,12 @@
                             addOptionToSelectControl(selectControl, key, variableValues[key]);
                         }
                         break;
+                    case 'jso':
+                        var variableValues = JSON.parse(filterDataSource);
+                        for (var key in variableValues) {
+                            addOptionToSelectControl(selectControl, key, variableValues[key]);
+                        }
+                        break;
                 }
             }
         });
@@ -406,7 +412,8 @@
         filterControl: undefined,
         filterData: undefined,
         filterDatepickerOptions: undefined,
-        filterStrictSearch: false
+        filterStrictSearch: false,
+        filterStartsWithSearch: false
     });
 
     $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
@@ -539,6 +546,13 @@
                         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') &&