Skip to content

Commit

Permalink
Add a ignoreClickToSelectOn option that takes an element and returns …
Browse files Browse the repository at this point in the history
…true or false.

The default implementation ignores clicks on <a> tags and <button> tags.
This fixes wenzhixin#3457.
  • Loading branch information
jfly committed Dec 13, 2017
1 parent 8944bb3 commit 8f7fce4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/_i18n/en/documentation/table-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,17 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
<td>false</td>
<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>
Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@

customSort: $.noop,

ignoreClickToSelectOn: function (element) {
return $.inArray(element.tagName, ['A', 'BUTTON']);
},

rowStyle: function (row, index) {
return {};
},
Expand Down Expand Up @@ -1911,7 +1915,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
Expand Down

0 comments on commit 8f7fce4

Please sign in to comment.