I have a Python script which generates an HTML table. The final column of the table contains checkboxes. I want to use the Shift key to select multiple checkboxes. So, I've incorporated this Javascript.
However, I'm sorting the table columns after loading using tablesorter (and after calling the above Javascript). Furthermore, the user can also sort columns by clicking on column headers. This results in the wrong checkboxes being selected after the user uses Shift-click.
So far I have tried:
- moving the select multiple checkboxes javascript to after the sorting (which seems logical to me), but then the sorting functionality does not work
- the other javascript answers to that question (How can I shift-select multiple checkboxes like GMail?) but then multi-select does not work
- other Googled code (like this) - but again multi-select does not work
The code:
<script src='shift-click-select.js'></script>
<script src='jquery-latest.js'></script>
<script src='jquery.tablesorter.min.js'></script>
<script>
//Javascript function to sort table "my_table" by default on first column (0,0) and then on second column (1) in ascending order (0).
$(function() {
$("#my_table").tablesorter({sortList:[[0,0],[1,0]]});
});
</script>
<table id="my_table" class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<td><input type="checkbox" name="%s" class="chkbox" /></td>
...
</table>
note: shift-click-select.js is from answer mention above.
My guess is that I might need to re-number the checkboxes every time the table is resorted, but I'm hoping there is an easier way?