Skip to content

Commit

Permalink
fix: filter ,sort and page on datatable (PnX-SI#310)
Browse files Browse the repository at this point in the history
* fix: filter ,sort and page on datatable

Missing changes to check according to event on table(sort, filter, page)
Refact code for ngOnChanges

Reviewed-by: andriac

* style(front): apply prettier

Reviewed-by: andriacap
  • Loading branch information
andriacap authored Feb 15, 2024
1 parent 9b5dc1f commit 8677eb0
Showing 1 changed file with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
OnInit,
Output,
SimpleChanges,
SimpleChange,
TemplateRef,
ViewChild,
} from '@angular/core';
Expand Down Expand Up @@ -290,9 +291,33 @@ export class MonitoringDatatableGComponent implements OnInit {
// }

ngOnChanges(changes: SimpleChanges) {
// IF prefered ngOnChanges compare to observable uncomment this:
if (changes['dataTableObj'] && this.dataTableObj && Object.keys(this.dataTableObj).length > 0) {
this.filters = {};
if (changes.activetabIndex) {
this.clearFilters();
}

if (changes.obj) {
this.updateDataTable(changes.obj);
}

if (changes.rows || changes.page) {
this.updateRowsAndPage();
}

for (const propName of Object.keys(changes)) {
switch (propName) {
case 'rowStatus':
this.setSelected();
break;
}
}
}

private clearFilters() {
this.filters = {};
}

private updateDataTable(objChanges: SimpleChange) {
if (this.dataTableObj && Object.keys(this.dataTableObj).length > 0) {
for (const objType in this.dataTableObj) {
this.objectsStatus[objType] = this._dataTableService.initObjectsStatus(
this.dataTableObj[objType].rows,
Expand All @@ -301,31 +326,24 @@ export class MonitoringDatatableGComponent implements OnInit {
}

this.activetabType = this.dataTableArray[this.activetabIndex].objectType;
this.dataTableObj[this.activetabType].rows.length > 0
? (this.columns = this._dataTableService.colsTable(
this.dataTableObj[this.activetabType].columns,
this.dataTableObj[this.activetabType].rows[0]
))
: null;
this.rows = this.dataTableObj[this.activetabType].rows;
this.page = this.dataTableObj[this.activetabType].page;
const dataTable = this.dataTableObj[this.activetabType];
if (dataTable.rows.length > 0) {
this.columns = this._dataTableService.colsTable(dataTable.columns, dataTable.rows[0]);
}
this.rows = dataTable.rows;
this.page = dataTable.page;
this.initPermissionAction();
}
}

if (changes['rows'] && this.rows && this.rows.length > 0) {
private updateRowsAndPage() {
if (this.rows && this.rows.length > 0) {
this.activetabType = this.dataTableArray[this.activetabIndex].objectType;
this.rows = this.dataTableObj[this.activetabType].rows;
this.page = this.dataTableObj[this.activetabType].page;
const dataTable = this.dataTableObj[this.activetabType];
this.rows = dataTable.rows;
this.page = dataTable.page;
this.initPermissionAction();
}

for (const propName of Object.keys(changes)) {
switch (propName) {
case 'rowStatus':
this.setSelected();
break;
}
}
}
navigateToAddChildren(_, row) {
this.addEvent.emit(row);
Expand Down

0 comments on commit 8677eb0

Please sign in to comment.