hjalmers / angular-generic-table

A generic table for Angular 2+. Generic table uses standard markup for tables ie. table, tr and td elements etc. and has support for expanding rows, global search, filters, sorting, pagination, export to CSV, column clicks, custom column rendering, custom export values.
https://hjalmers.github.io/angular-generic-table/
MIT License
104 stars 55 forks source link

Filter table when/before page loads #202

Closed Tompish closed 6 years ago

Tompish commented 6 years ago

Hi! When the webpage first loads, I want the table to be filtered by default. I try to do this by simply writing this.myTable.gtApplyFilter({ RandomColumn: 1 }); However, i keep getting this error message: image

I have tried to apply the filter in all lifecycle hooks except for ngOnDestroy. I can manually filter the code without any problem once the page has loaded, so i know the filter is correct.

Tompish commented 6 years ago

For future refences, the error message is recieved when sending a non-string property to gtApplyfilter(). The confusing part was angular2 rather than the GenericTable. In the html i had an element which looked like this: <button (click)="applyFilter('1')">Filter</button> And the function applyFilter(): public applyFilter = function(filter: number){ this.myGenericTable.gtApplyFilter({Id: filter}); } And when calling the function from the HTML it worked perfectly and no error message. But when calling it from the typescipt file in the exact same way, i got the error message saying the function expects a number. If i changed it to a number (i.e. no apostrophes this.applyFilter(1)), i got the error message attached in my first post.