1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-24 15:27:43 +01:00

feat: Cambia stato alla checkbox dell'header quando cambi stato a una checkbox di una riga

This commit is contained in:
Maicol Battistini 2021-11-23 21:24:29 +01:00
parent 5de58ba5e4
commit 4e270c9994
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A

View File

@ -1,3 +1,6 @@
import {type Cash} from 'cash-dom/dist/cash';
import {inRange} from 'lodash-es';
import Component from '../Component.jsx';
/**
@ -16,4 +19,30 @@ export default class TableCell extends Component {
return <td {...this.attrs.all()}>{vnode.children}</td>;
}
oncreate(vnode) {
super.oncreate(vnode);
const checkboxes = (): Cash => $(this.element)
.closest('.mdc-data-table')
.find('tbody tr[checkable] mwc-checkbox');
const cell: Cash = $(this.element);
cell.children('mwc-checkbox').on('change', (event) => {
const row = cell.parent();
row.toggleClass('mdc-data-table__row--selected');
const headerCheckbox = cell.closest('.mdc-data-table').find('thead th mwc-checkbox');
const checks = checkboxes();
const checked = checks.filter('[checked]');
if (inRange(checked.length, 1, checks.length)) {
headerCheckbox.prop('indeterminate', true);
headerCheckbox.prop('checked', false);
} else {
headerCheckbox.prop('checked', checks.length === checked.length);
headerCheckbox.prop('indeterminate', false);
}
});
}
}