shift-select multiple checkboxes like GMail?
HTML
<table id="dataTable">
<tbody>
<tr>
<td><input type="checkbox"></td>
</tr>
<tr>
<td><input type="checkbox"></td>
</tr>
<tr>
<td><input type="checkbox"></td>
</tr>
<tr>
<td><input type="checkbox"></td>
</tr>
</tbody>
</table>
JavaScript
$(document).ready(function() {
var $chkboxes = $('#dataTable'); //Main Wrap
var $range = '#dataTable tbody'; //specify detail Wrap
var $indexWrapp = 'tr'; //index count (could be also <li> or <div>)
var lastChecked = null;
var $checkboxes = 'input[type="checkbox"]'; // specilly checkboxes only?
$chkboxes.on('click', $checkboxes, function(e) {
if (!lastChecked) {
lastChecked = $(this).closest($indexWrapp).index();
lastCheckedInput = $(this).prop('checked');
return;
}
var start = lastChecked;
var end = $(this).closest($indexWrapp).index();
alert(start)
alert(end)
if (e.shiftKey) {
$($range + ' ' + $indexWrapp).each(function() {
$currIndex = $(this).index();
if ($currIndex >= start && $currIndex <= end) {
$(this).find($checkboxes).prop('checked', lastCheckedInput);
}
})
}
lastCheckedInput = $(this).prop('checked');
lastChecked = $(this).closest($indexWrapp).index();
});
});