question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using checkbox and sortable on same column sorts when click on checkAll checkbox

See original GitHub issue

Using checkbox and sortable on same column sorts when you click on the checkAll checkbox. I would expect for sorting not to be affected when you click the checkAll checkbox. If you click on the checkAll button instead of the checkbox, the problem does not occur.

With pagination the problem is much more obvious because the checked rows seem to disappear when you click the selectAll checkbox.

Reproduced with the Online Editor on Chrome Version 78.0.3904.87 on Windows 10 with the following setup:

<div id="toolbar">
  <button id="button" class="btn btn-secondary">checkAll</button>
  <button id="button2" class="btn btn-secondary">uncheckAll</button>
</div>
<table
  id="table"
  data-toggle="table"
  data-toolbar="#toolbar"
  data-height="460"
  data-url="json/data1.json"
  data-pagination="true"
  data-page-size="5">
  <thead>
    <tr>
      <th data-field="state" data-checkbox="true" data-sortable="true" ></th>
      <th data-field="id">ID</th>
      <th data-field="name">Item Name</th>
      <th data-field="price">Item Price</th>
    </tr>
  </thead>
</table>

<script>
  var $table = $('#table')
  var $button = $('#button')
  var $button2 = $('#button2')

  $(function() {
    $button.click(function () {
      $table.bootstrapTable('checkAll')
    })
    $button2.click(function () {
      $table.bootstrapTable('uncheckAll')
    })
  })
</script>

To prevent this, I did the following:

        $('input[name="btSelectAll"]').off('click').on("click", (function(e) {
        let checked = $(this).prop("checked");
        $table.bootstrapTable(checked ? "checkAll" : "uncheckAll");
        e.stopPropagation();
        }));

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wenzhixincommented, Nov 13, 2019

I don’t understand why you want to use the checkbox and sortable on the same column.

0reactions
wenzhixincommented, Nov 13, 2019

Fixed in #4697

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent click on "Select all" checkbox to affect header ...
I am using jQuery DataTables plugin. I created ...
Read more >
Best practice for sorting and being able to "check all" in a table ...
I have a table as part of a form for which users can click the header row to sort by that column (and...
Read more >
row-reorder, column sorting, and checkboxes - DataTables
I'm trying to add a checkbox to each field with a 'select all' option in the column header, I have it working at...
Read more >
checkbox check/uncheck all not working after insert tablesorter
i have a gridview with a column of checkboxes. the check_all function work well but when i insert tablesorter to sort my gridview, ......
Read more >
How to place 'check-all' checkbox in kendo grid column template
Also, for some reason the checkbox in the header does not get checked when I click it, instead when I click it, it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found