浏览代码

Merge pull request #1934 from Real-Gecko/develop

Added checkInvert method, that inverts current selections
wenzhixin 10 年之前
父节点
当前提交
770fe4fcf2
共有 2 个文件被更改,包括 19 次插入0 次删除
  1. 5 0
      docs/_i18n/en/documentation/methods.md
  2. 14 0
      src/bootstrap-table.js

+ 5 - 0
docs/_i18n/en/documentation/methods.md

@@ -196,6 +196,11 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>Uncheck all current page rows.</td>
         <td>Uncheck all current page rows.</td>
     </tr>
     </tr>
     <tr>
     <tr>
+        <td>checkInvert</td>
+        <td>none</td>
+        <td>Invert check of current page rows. Triggers onCheckSome and onUncheckSome events.</td>
+    </tr>
+    <tr>
         <td>check</td>
         <td>check</td>
         <td>index</td>
         <td>index</td>
         <td>Check a row, the row index start with 0.</td>
         <td>Check a row, the row index start with 0.</td>

+ 14 - 0
src/bootstrap-table.js

@@ -2439,6 +2439,20 @@
         this.checkAll_(false);
         this.checkAll_(false);
     };
     };
 
 
+    BootstrapTable.prototype.checkInvert = function () {
+        var that = this;
+        var rows = that.$selectItem.filter(':enabled');
+        var checked = rows.filter(':checked');
+        rows.each(function() {
+            $(this).prop('checked', !$(this).prop('checked'));
+        });
+        that.updateRows();
+        that.updateSelected();
+        that.trigger('uncheck-some', checked);
+        checked = that.getSelections();
+        that.trigger('check-some', checked);
+    };
+
     BootstrapTable.prototype.checkAll_ = function (checked) {
     BootstrapTable.prototype.checkAll_ = function (checked) {
         var rows;
         var rows;
         if (!checked) {
         if (!checked) {