Skip to content

Commit

Permalink
Merge pull request wenzhixin#3490 from jfly/issue-3457
Browse files Browse the repository at this point in the history
Don't select the row when <a> tags or <button> tags are clicked.
  • Loading branch information
wenzhixin authored Dec 13, 2017
2 parents 7733c32 + 8f7fce4 commit de8cbcf
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 @@ -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
Expand Down

0 comments on commit de8cbcf

Please sign in to comment.