mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-24 23:37:51 +01:00
feat: ✨ Cambia stato alla checkbox dell'header quando cambi stato a una checkbox di una riga
This commit is contained in:
parent
5de58ba5e4
commit
4e270c9994
@ -1,3 +1,6 @@
|
|||||||
|
import {type Cash} from 'cash-dom/dist/cash';
|
||||||
|
import {inRange} from 'lodash-es';
|
||||||
|
|
||||||
import Component from '../Component.jsx';
|
import Component from '../Component.jsx';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,4 +19,30 @@ export default class TableCell extends Component {
|
|||||||
|
|
||||||
return <td {...this.attrs.all()}>{vnode.children}</td>;
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user