Skip to content

Commit d10ba59

Browse files
committed
Corrected handling of 'label' nodes. Checkboxes are no longer centered by default.
1 parent b2a5464 commit d10ba59

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

css/dataTables.checkboxes.css

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
table.dataTable.dt-checkboxes-select tbody tr,
2-
table.dataTable thead .dt-checkboxes-select-all {
2+
table.dataTable thead th.dt-checkboxes-select-all,
3+
table.dataTable tbody td.dt-checkboxes-cell {
34
cursor: pointer;
45
}
56

6-
table.dataTable thead .dt-checkboxes-select-all {
7-
text-align: center;
8-
}
9-
107
div.dataTables_wrapper span.select-info,
118
div.dataTables_wrapper span.select-item {
129
margin-left: 0.5em;

js/dataTables.checkboxes.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ Checkboxes.prototype = {
141141
};
142142

143143
if(ctx.aoColumns[i].sClass === ''){
144-
colOptions['className'] = 'dt-body-center';
144+
colOptions['className'] = 'dt-checkboxes-cell';
145+
} else {
146+
colOptions['className'] = ctx.aoColumns[i].sClass + ' dt-checkboxes-cell';
145147
}
146148

147149
if(ctx.aoColumns[i].sWidthOrig === null){
@@ -263,14 +265,6 @@ Checkboxes.prototype = {
263265
// Prevent row selection
264266
e.preventDefault();
265267
}
266-
267-
// WORKAROUND: Prevent duplicate checkbox select/deselect event
268-
// when "label" node is used in the column containing checkbox
269-
if(ctx.aoColumns[colIdx].checkboxes){
270-
if(originalEvent.target.nodeName.toLowerCase() === 'label'){
271-
e.preventDefault();
272-
}
273-
}
274268
});
275269

276270
// Handle row select/deselect event
@@ -295,7 +289,7 @@ Checkboxes.prototype = {
295289
self.onDraw(e);
296290
});
297291

298-
// Handles checkbox click event
292+
// Handle checkbox click event
299293
$tableBody.on('click.dtCheckboxes', 'input.dt-checkboxes', function(e){
300294
self.onClick(e, this);
301295
});
@@ -310,6 +304,21 @@ Checkboxes.prototype = {
310304
$('input[type="checkbox"]', this).not(':disabled').trigger('click');
311305
});
312306

307+
// If row selection is disabled
308+
if(!hasCheckboxesSelectRow){
309+
// Handle click on cell containing checkbox
310+
$tableContainer.on('click.dtCheckboxes', 'tbody td.dt-checkboxes-cell', function(e) {
311+
$('input[type="checkbox"]', this).not(':disabled').trigger('click');
312+
});
313+
}
314+
315+
// Handle click on label node in heading containing "Select all" control
316+
// and in cell containing checkbox
317+
$tableContainer.on('click.dtCheckboxes', 'thead th.dt-checkboxes-select-all label, tbody td.dt-checkboxes-cell label', function(e) {
318+
// Prevent default behavior
319+
e.preventDefault();
320+
});
321+
313322
// Handle click on "Select all" control in floating fixed header
314323
$(document).on('click.dtCheckboxes', '.fixedHeader-floating thead th.dt-checkboxes-select-all input[type="checkbox"]', function(e){
315324
// If FixedHeader is enabled in this instance

0 commit comments

Comments
 (0)