Filip
Filip

Reputation: 143

How get angular ng2-smart-table filtering and sorting external events?

I have REST API backend so all sorting, filtering and pagination is manages by backend. On my Angular aplictation I want to display data at ng2 smart table. After clicking on table header column name (sorting asc, desc) is table content sorted only on frontend side. I need to get some event to call REST API to updated data ( Not only frontend sorting ), the same I need to filtering by headers input fields. After typing to filtering input I need to call rest api to get filtered data from backend.

If I set table mode external I get events only for creating new item, deleting item and editing event. How could I get sorting and filtering events?

I tried everithing from smart table doc but in docs are solution only for create delete and update external event not sorting and filtering

Upvotes: 1

Views: 4278

Answers (1)

Sachin Shah
Sachin Shah

Reputation: 4533

Try to add this code in your ngOnInit()

this.tableData.onChanged().subscribe((change) => {

  if (change.action === 'filter') {        
    // Do whatever you want with the filter event

  }
});

Note: this.tableData is your LocalDataSource.

Link for more details

Upvotes: 8

Related Questions