0
votes

I'm using ng2-smart-table I'm updating the information with a setInterval function every 2 mins I receive new information.

The issue is when I'm filtering, sorting or using the pagination of the data table the interval is triggered and the data table return to default filter and sort etc.

I'm looking for some way to update pendingAlerts but without affecting the current filter or sort in the data table. I'm thinking in affecting directly every instance of the array but I don't know if it is a good approach.

HTML

<ng2-smart-table (userRowSelect)="onRowSelected($event)" [settings]="settings" [source]="pendingAlerts"></ng2-smart-table>

I'm using an storedata with a observable pattern to retrieve the information I think that isn't relevant to show this code

Component

...
pendingAlerts: Pending[] =[];
...
next = (data: Pending[]) => {
    console.log("Receiving info from observer"+ data.length);
    this.pendingAlerts = data;   

  }
1

1 Answers

0
votes

The answer is by using LocalDataSource class and load function to load data. and you will keep your filter and sorting configuration.

Component

pendingAlerts: LocalDataSource;
count: number = 0;
ngOnInit() {    
  this.pendingAlerts = new LocalDataSource([]); 
  this.pendingAlerts.onChanged().subscribe(res =>{
      this.count = this.pendingAlerts.count();
  });  
}

  next = (data: Pending[]) => {
    console.log("Receiving info from observer"+ data.length);
    this.pendingAlerts.load(data);   

  }