ngx-datatable
ngx-datatable copied to clipboard
How do i make all checkbox checked/unchecked from externally?
I am having ngx datatable inside other ngx datatable like parent and child, how can i make selected all checkbox of child datatable from parent datatable on change of checkbox.
While digging into ngx-datatable checkbox found that its possible by using allRowsSelected and selectFn properties, but how can i call it from outside datatable.
<ng-template #headerTemplate ngx-datatable-header-template let-value="value" let-allRowsSelected="allRowsSelected" let-selectFn="selectFn">
<input type="checkbox" [checked]="allRowsSelected" (change)="selectFn(!allRowsSelected)" />
</ng-template>
Here is the screenshot
You must remember that ngx-datatable uses onPush changeDetection, so you should always work with immutable operations to return a new variable reference, like:
this.selected = [... this.rows];
This should select all your rows.
To unselect all, just clear the selected variable:
this.selected = [];
@dionatan-g that really helped, thanks!!