Bug #18867: Fixed multiple issues with yii\grid\CheckboxColumn

- "check all" checkbox not being checked on page load when all data row checkboxes are initially checked
- clicking checkboxes triggered "change" event for other checkboxes that do not change their state
- "check all" checkbox not being checked when disabled checkboxes are present and clicking last non-checked data row checkbox
This commit is contained in:
PowerGamer1
2022-12-28 17:35:42 +02:00
committed by GitHub
parent 38aff47b45
commit 41d232f25e
3 changed files with 18 additions and 16 deletions

View File

@ -188,16 +188,17 @@
if (!options.multiple || !options.checkAll) {
return;
}
var checkAll = "#" + id + " input[name='" + options.checkAll + "']";
var inputs = options['class'] ? "input." + options['class'] : "input[name='" + options.name + "']";
var inputsEnabled = "#" + id + " " + inputs + ":enabled";
initEventHandler($grid, 'checkAllRows', 'click.yiiGridView', checkAll, function () {
$grid.find(inputs + ":enabled").prop('checked', this.checked).change();
var checkAllInput = "input[name='" + options.checkAll + "']";
var inputs = (options['class'] ? "input." + options['class'] : "input[name='" + options.name + "']") + ":enabled";
initEventHandler($grid, 'checkAllRows', 'click.yiiGridView', "#" + id + " " + checkAllInput, function () {
$grid.find(inputs + (this.checked ? ":not(:checked)" : ":checked")).prop('checked', this.checked).change();
});
initEventHandler($grid, 'checkRow', 'click.yiiGridView', inputsEnabled, function () {
var handler = function () {
var all = $grid.find(inputs).length == $grid.find(inputs + ":checked").length;
$grid.find("input[name='" + options.checkAll + "']").prop('checked', all).change();
});
$grid.find(checkAllInput + (all ? ":not(:checked)" : ":checked")).prop('checked', all).change();
};
initEventHandler($grid, 'checkRow', 'click.yiiGridView', "#" + id + " " + inputs, handler);
handler(); // Ensure "check all" checkbox is checked on page load if all data row checkboxes are initially checked.
},
getSelectedRows: function () {