Skip to content

Commit

Permalink
fix: reset filter if ngx-datable changes
Browse files Browse the repository at this point in the history
Filter now works even if you input filter from sitegroups components
and then decide to see details of datatable element
and add new filter for sitegroup's sites child

Reviewed-by: andriacap
[Refs ticket]: #4
  • Loading branch information
andriacap committed Jan 24, 2023
1 parent 5baaaa6 commit 0830024
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class MonitoringDatatableGComponent implements OnInit {
initDatatable() {
console.log("Inside initDatatable");
console.log("this.rows", this.rows);
this.filters = {};
this.filterSubject.pipe(debounceTime(500)).subscribe(() => {
this.filter();
});
Expand Down Expand Up @@ -179,13 +178,17 @@ export class MonitoringDatatableGComponent implements OnInit {
ngOnChanges(changes: SimpleChanges) {
console.log("inside ngOnChanges");
console.log("changes", changes);
if (changes["rows"] && this.rows) {
if (changes["rows"] && this.rows && this.rows.length > 0) {
this.columns = this._dataTableService.colsTable(
this.colsname,
this.rows[0]
);
}

if (changes["colsname"]) {
this.filters = {};
}

if (changes["obj"] && this.obj) {
this.objectsStatus,
(this.rowStatus = this._dataTableService.initObjectsStatus(
Expand All @@ -196,7 +199,7 @@ export class MonitoringDatatableGComponent implements OnInit {
for (const propName of Object.keys(changes)) {
const chng = changes[propName];
const cur = chng.currentValue;
const pre = chng.currentValue;
const pre = chng.previousValue;
switch (propName) {
case "rowStatus":
this.setSelected();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Component, OnInit, Input } from "@angular/core";
import { SitesGroupService } from "../../services/sites_group.service";
import {
columnNameSiteGroup,
} from "../../class/monitoring-sites-group";
import { columnNameSiteGroup } from "../../class/monitoring-sites-group";
import { IPaginated, IPage } from "../../interfaces/page";
import {
Router,
Expand Down Expand Up @@ -41,15 +39,15 @@ export class MonitoringSitesGroupsComponent implements OnInit {
path: string;
currentRoute: string = "";
id: string | null;
changeFromTable: boolean = false;

private routerSubscription: Subscription;

constructor(
private _sites_group_service: SitesGroupService,
private router: Router,
private _Activatedroute: ActivatedRoute
) // private _routingService: RoutingService
{
private _Activatedroute: ActivatedRoute // private _routingService: RoutingService
) {
// TODO: Try to refactor into routingService ?
// console.log(this.id)
// this.id = this._routingService.id
Expand Down Expand Up @@ -161,20 +159,22 @@ export class MonitoringSitesGroupsComponent implements OnInit {
console.log("inside getDataAccording to path, params", params);
params["id_sites_group"] = this.id;
this.displayDetails = true;
this.getSitesGroupsById(
(page = 1),
(params = { id_sites_group: this.id })
);
if (this.changeFromTable == false) {
this.getSitesGroupsById(1, (params = { id_sites_group: this.id }));
}
this.getSitesGroupsChild(page, params);
this.changeFromTable = false;
} else {
console.log("inside getDataAccording to path, params", params);
this.getSitesGroups(page, params);
}
// });
}

setPage($event) {
console.log("setPage Sitesgroups Components");
this.getDataAccordingTopath($event.page + 1, this.filters);
this.changeFromTable = true;
this.getDataAccordingTopath($event.filter + 1, this.filters);
}

onSortEvent(filters) {
Expand All @@ -186,6 +186,11 @@ export class MonitoringSitesGroupsComponent implements OnInit {
onFilterEvent(filters) {
console.log("onFilterEvent sitegroups component, filters", filters);
this.filters = filters;
this.changeFromTable = true;
console.log(
"onFilterEvent sitegroups component, this.filters",
this.filters
);
this.getDataAccordingTopath(1, this.filters);
}

Expand Down

0 comments on commit 0830024

Please sign in to comment.