Skip to content

Commit

Permalink
Add disabled state to table treetable action btns
Browse files Browse the repository at this point in the history
  • Loading branch information
fateeand committed Oct 26, 2023
1 parent f1b8cff commit f6b1a06
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<div>{{ toolbarTitle }}</div>
<div *ngIf="showGlobalFilter" class="cps-table-tbar-global-filter">
<cps-input
#globalFilterComp
prefixIcon="search"
[placeholder]="globalFilterPlaceholder"
(valueChanged)="onFilterGlobal($event)"
Expand All @@ -64,6 +65,7 @@
class="cps-table-tbar-btn-on-select">
<cps-button
label="Remove"
[disabled]="removeBtnOnSelectDisabled"
color="prepared"
type="borderless"
icon="remove"
Expand All @@ -76,6 +78,7 @@
class="cps-table-tbar-btn-on-select">
<cps-button
[label]="additionalBtnOnSelectTitle"
[disabled]="additionalBtnOnSelectDisabled"
color="prepared"
type="borderless"
[size]="toolbarSize"
Expand All @@ -85,6 +88,7 @@
<div *ngIf="showActionBtn" class="cps-table-tbar-action-btn">
<cps-button
[label]="actionBtnTitle"
[disabled]="actionBtnDisabled"
color="prepared"
type="outlined"
[size]="toolbarSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ export class CpsTableComponent implements OnInit, AfterViewChecked, OnChanges {
@Input() globalFilterFields: string[] = [];

@Input() showRemoveBtnOnSelect = true;
@Input() removeBtnOnSelectDisabled = false;

@Input() showAdditionalBtnOnSelect = false;
@Input() additionalBtnOnSelectTitle = 'Select action';
@Input() additionalBtnOnSelectDisabled = false;

@Input() showActionBtn = false;
@Input() actionBtnTitle = 'Action';
@Input() actionBtnDisabled = false;

@Input() showExportBtn = false;
@Input() exportFilename = 'download';
Expand Down Expand Up @@ -173,6 +176,9 @@ export class CpsTableComponent implements OnInit, AfterViewChecked, OnChanges {
@ViewChild('primengTable', { static: true })
primengTable!: Table;

@ViewChild('globalFilterComp')
globalFilterComp!: CpsInputComponent;

selectedRows: any[] = [];

virtualScrollItemSize = 0;
Expand Down Expand Up @@ -287,6 +293,8 @@ export class CpsTableComponent implements OnInit, AfterViewChecked, OnChanges {
}

ngOnChanges(changes: SimpleChanges): void {
if (this.loading) this.clearGlobalFilter();

const dataChanges = changes?.data;
if (
dataChanges?.previousValue?.length !== dataChanges?.currentValue?.length
Expand All @@ -297,6 +305,10 @@ export class CpsTableComponent implements OnInit, AfterViewChecked, OnChanges {
}
}

clearGlobalFilter() {
this.globalFilterComp?.clear();
}

onSelectionChanged(selection: any[]) {
this.selectionChanged.emit(selection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<div>{{ toolbarTitle }}</div>
<div *ngIf="showGlobalFilter" class="cps-treetable-tbar-global-filter">
<cps-input
#globalFilterComp
prefixIcon="search"
[placeholder]="globalFilterPlaceholder"
(valueChanged)="onFilterGlobal($event)"
Expand All @@ -66,6 +67,7 @@
class="cps-treetable-tbar-btn-on-select">
<cps-button
label="Remove"
[disabled]="removeBtnOnSelectDisabled"
color="prepared"
type="borderless"
icon="remove"
Expand All @@ -78,6 +80,7 @@
class="cps-treetable-tbar-btn-on-select">
<cps-button
[label]="additionalBtnOnSelectTitle"
[disabled]="additionalBtnOnSelectDisabled"
color="prepared"
type="borderless"
[size]="toolbarSize"
Expand All @@ -87,6 +90,7 @@
<div *ngIf="showActionBtn" class="cps-treetable-tbar-action-btn">
<cps-button
[label]="actionBtnTitle"
[disabled]="actionBtnDisabled"
color="prepared"
type="outlined"
[size]="toolbarSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,15 @@ export class CpsTreeTableComponent
@Input() globalFilterFields: string[] = [];

@Input() showRemoveBtnOnSelect = true;
@Input() removeBtnOnSelectDisabled = false;

@Input() showAdditionalBtnOnSelect = false;
@Input() additionalBtnOnSelectTitle = 'Select action';
@Input() additionalBtnOnSelectDisabled = false;

@Input() showActionBtn = false;
@Input() actionBtnTitle = 'Action';
@Input() actionBtnDisabled = false;

@Input() showDataReloadBtn = false;

Expand Down Expand Up @@ -180,6 +183,9 @@ export class CpsTreeTableComponent
@ViewChild('primengTreeTable', { static: true })
primengTreeTable!: TreeTable;

@ViewChild('globalFilterComp')
globalFilterComp!: CpsInputComponent;

selectedColumns: { [key: string]: any }[] = [];

rowOptions: { label: string; value: number }[] = [];
Expand Down Expand Up @@ -285,6 +291,8 @@ export class CpsTreeTableComponent
}

ngOnChanges(changes: SimpleChanges): void {
if (this.loading) this.clearGlobalFilter();

const dataChanges = changes?.data;
if (dataChanges?.previousValue !== dataChanges?.currentValue) {
this.selectedRows = [];
Expand All @@ -297,6 +305,10 @@ export class CpsTreeTableComponent
window.removeEventListener('resize', this._onWindowResize.bind(this));
}

clearGlobalFilter() {
this.globalFilterComp?.clear();
}

private _onWindowResize() {
this.defScrollHeightPx = this.scrollableBody.clientHeight;
}
Expand Down

0 comments on commit f6b1a06

Please sign in to comment.