Skip to content

Angular - Multiselect extensible table #22587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,40 @@
[rows]="data"
[count]="recordsTotal"
[list]="list"
[selectionType]="selectable ? _selectionType : undefined"
(activate)="tableActivate.emit($event)"
(select)="onSelect($event)"
[selected]="selected"
>
@if(selectable) {
<ngx-datatable-column [width]="50" [sortable]="false" [canAutoResize]="false" [draggable]="false" [resizeable]="false">

<ng-template ngx-datatable-header-template let-value="value" let-allRowsSelected="allRowsSelected"
let-selectFn="selectFn">
@if (_selectionType !== 'single') {
<div class="form-check">
<input class="form-check-input table-check" type="checkbox" [checked]="allRowsSelected"
(change)="selectFn(!allRowsSelected)" />
</div>
}
</ng-template>

<ng-template ngx-datatable-cell-template let-value="value" let-row="row" let-isSelected="isSelected"
let-onCheckboxChangeFn="onCheckboxChangeFn">
@if(_selectionType === 'single') {
<div class="h-100 form-check form-check-sm form-check-custom form-check-solid">
<input class="form-check-input" type="radio" [checked]="isSelected" (change)="onCheckboxChangeFn($event)" />
</div>
}
@if (_selectionType !== 'single') {
<div class="h-100 form-check form-check-sm form-check-custom form-check-solid">
<input class="form-check-input" type="checkbox" [checked]="isSelected" (change)="onCheckboxChangeFn($event)" />
</div>
}
</ng-template>

</ngx-datatable-column>
}
@if (actionsTemplate || (actionList.length && hasAtLeastOnePermittedAction)) {
<ngx-datatable-column
[name]="actionsText | abpLocalization"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { AsyncPipe, formatDate, NgComponentOutlet, NgTemplateOutlet } from '@ang
import { Observable, filter, map } from 'rxjs';

import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { NgxDatatableModule, SelectionType } from '@swimlane/ngx-datatable';

import {
ABP,
Expand Down Expand Up @@ -102,6 +102,17 @@ export class ExtensibleTableComponent<R = any> implements OnChanges, AfterViewIn

@Output() tableActivate = new EventEmitter();

@Input() selectable = false;

@Input() set selectionType(value: SelectionType | string) {
this._selectionType = typeof value === 'string' ? SelectionType[value] : value;
}
_selectionType: SelectionType = SelectionType.multiClick;


@Input() selected: any[] = [];
@Output() selectionChange = new EventEmitter<any[]>();

hasAtLeastOnePermittedAction: boolean;

readonly columnWidths!: number[];
Expand Down Expand Up @@ -229,6 +240,12 @@ export class ExtensibleTableComponent<R = any> implements OnChanges, AfterViewIn
return visibleActions.length > 0;
}

onSelect({ selected }) {
this.selected.splice(0, this.selected.length);
this.selected.push(...selected);
this.selectionChange.emit(selected);
}

ngAfterViewInit(): void {
this.list?.requestStatus$?.pipe(filter(status => status === 'loading')).subscribe(() => {
this.data = [];
Expand Down