Browse Source

New methods to select rows by value

New methods to select rows by value or array of values. You can pass {field:"column_name", value:"value1"} to check/uncheck by single value or {field:"column_name", value:["value1","value2","value3"]} to check/unchek by multiple values.
macias3 11 years ago
parent
commit
39173f2e54
1 changed files with 22 additions and 0 deletions
  1. 22 0
      src/bootstrap-table.js

+ 22 - 0
src/bootstrap-table.js

@@ -1542,6 +1542,27 @@
         this.updateSelected();
         this.updateSelected();
         this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
         this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
     };
     };
+    
+    BootstrapTable.prototype.checkBy = function (obj) {
+        this.checkBy_(true, obj);
+    };
+
+    BootstrapTable.prototype.uncheckBy = function (obj) {
+        this.checkBy_(false, obj);
+    };
+    
+    BootstrapTable.prototype.checkBy_ = function (checked, obj) {
+        var that = this;
+        var is_array = $.isArray(obj.value);
+        $.each(this.data, function (index, row) {
+            if(is_array ? $.inArray(row[obj.field], obj.value) != -1 : row[obj.field] == obj.value) {
+                that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
+                row[that.header.stateField] = checked;
+                that.trigger(checked ? 'check' : 'uncheck', row);  
+            }
+        });
+        this.updateSelected();
+    };
 
 
     BootstrapTable.prototype.destroy = function () {
     BootstrapTable.prototype.destroy = function () {
         this.$el.insertBefore(this.$container);
         this.$el.insertBefore(this.$container);
@@ -1643,6 +1664,7 @@
         'mergeCells',
         'mergeCells',
         'checkAll', 'uncheckAll',
         'checkAll', 'uncheckAll',
         'check', 'uncheck',
         'check', 'uncheck',
+        'checkBy', 'uncheckBy',
         'refresh',
         'refresh',
         'resetView',
         'resetView',
         'destroy',
         'destroy',