Browse Source

Merge pull request #3490 from jfly/issue-3457

Don't select the row when <a> tags or <button> tags are clicked.
文翼 8 years ago
parent
commit
de8cbcf4b8
2 changed files with 16 additions and 1 deletions
  1. 11 0
      docs/_i18n/en/documentation/table-options.md
  2. 5 1
      src/bootstrap-table.js

+ 11 - 0
docs/_i18n/en/documentation/table-options.md

@@ -525,6 +525,17 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>True to select checkbox or radiobox when clicking rows.</td>
     </tr>
     <tr>
+        <td>ignoreClickToSelectOn</td>
+        <td>data-ignore-click-to-select-on</td>
+        <td>Function</td>
+        <td><code>{ return $.inArray(element.tagName, ['A', 'BUTTON']); }</code></td>
+        <td>
+        Takes one parameters:<br>
+        element: the element clicked on.<br>
+        Return true if the click should be ignored, false if the click should cause the row to be selected. This option is only relevant if clickToSelect is true.
+        </td>
+    </tr>
+    <tr>
         <td>singleSelect</td>
         <td>data-single-select</td>
         <td>Boolean</td>

+ 5 - 1
src/bootstrap-table.js

@@ -394,6 +394,10 @@
 
         customSort: $.noop,
 
+        ignoreClickToSelectOn: function (element) {
+            return $.inArray(element.tagName, ['A', 'BUTTON']);
+        },
+
         rowStyle: function (row, index) {
             return {};
         },
@@ -1902,7 +1906,7 @@
             that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
 
             // if click to select - then trigger the checkbox/radio click
-            if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect) {
+            if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect && that.options.ignoreClickToSelectOn(e.target)) {
                 var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
                 if ($selectItem.length) {
                     $selectItem[0].click(); // #144: .trigger('click') bug