Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular http return Mat Table filter data to specific columns

I want to filter the api return based specific column in mat-table. In my case , I want the the table only show finished status only. right now I manage to display the data on the mat table

here is my component.ts

export class EarningComponent implements OnInit {
  bookings: any = [];
  jobs:any = [];
  product:any =[];
  filterbooking:any =[];

  displayedColumns: string[] = ['id','title','status','painter_name','earning'];
  dataSource = new MatTableDataSource();

  constructor(private http: HttpClient) {}

  ngOnInit() {
    this.getlist()
  }

  getlist() {
    const body = {
      opcode: 'order_list',
      size: 20,
      page: 1,
      sign: 'e5111c807c49a330399b4ca36a27162',
    };
    this.http
      .post<any>('http://api.1shikj.com/cgi-bin/operate', body)
      .subscribe((data) => {
        this.bookings = data.data.data;
      });
  }
}

here is my output
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to filter the array being returned from you http request, then you can apply the .filter() method to that array.

this.bookings = data.data.data.filter(booking=>booking.status==='finished');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading