shift multiselect checkbox - Free Download Multiple Selection For Checkboxes - shiftMultiSelect.js

Free Download Multiple Selection For Checkboxes – shiftMultiSelect.js

Posted on

This time I will share jQuery Plugin and tutorial about Multiple Selection For Checkboxes – shiftMultiSelect.js, hope it will help you in programming stack.

shift multiselect checkbox - Free Download Multiple Selection For Checkboxes - shiftMultiSelect.js
File Size: 3.82 KB
Views Total: 1127
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

shiftMultiSelect.js is a tiny jQuery plugin that allows the user to select/deselect multiple rows in an HTML table by holding the Shift key and clicking associated checkboxes.

Additionally, it provides a Check All functionality that enables the user to select/deselect all rows in your HTML table with a single click.

How to use it:

1. Add a group of checkboxes to table rows as follows. Note that each checkbox must have a unique ID.

01 <table class="table">
02   <thead>
03     <tr>
04       <th scope="col">#</th>
05       <th scope="col">First</th>
06       <th scope="col">Last</th>
07       <th scope="col">Handle</th>
08     </tr>
09   </thead>
10   <tbody>
11     <tr>
12       <th scope="row"><input type="checkbox" id="id_chk1" class="checkRow" value="1" /></th>
13       <td>Mark</td>
14       <td>Otto</td>
15       <td>@mdo</td>
16     </tr>
17     <tr>
18       <th scope="row"><input type="checkbox" id="id_chk2" class="checkRow" value="2" /></th>
19       <td>Jacob</td>
20       <td>Thornton</td>
21       <td>@fat</td>
22     </tr>
23     <tr>
24       <th scope="row"><input type="checkbox" id="id_chk3" class="checkRow" value="3" /></th>
25       <td>Larry</td>
26       <td>the Bird</td>
27       <td>@<a href="https://www.jqueryscript.net/tags.php?/twitter/">twitter</a></td>
28     </tr>
29   </tbody>
30 </table>

2. Create a ‘Master’ checkbox input to check/uncheck all table rows.

1 <thead>
2   <tr>
3     <th scope="col"><input type="checkbox" name='checkboxMaster' /></th>
4     <th scope="col">First</th>
5     <th scope="col">Last</th>
6     <th scope="col">Handle</th>
7   </tr>
8 </thead>

3. Load the main script shiftMultiSelect.js after jQuery.

1 <script src="/path/to/cdn/jquery.slim.min.js"></script>
2 <script src="/path/to/shiftMultiSelect.js"></script>

4. Get the checked values.

1 $(':checkbox').change(function() {
2   console.log(checkValArray)
3 });
4 => ["1", "2", "3", "4", "5"]

5. Use CSS to highlight tables rows that are checked.

1 .table-primary, .table-primary>th, .table-primary>td {
2   background-color: #7F8C8D;
3   color: #fff;
4 }

This awesome jQuery plugin is developed by ryandougc. For more Advanced Usages, please check the demo page or visit the official website.