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

Implement Search in Lazy Loading ? #144

Closed rullymartanto closed 6 years ago

rullymartanto commented 6 years ago

hei, I have read this code

<input class="form-control form-control-sm mr-sm-2 mb-3 mb-sm-0" #search (keyup)="myTable.gtSearch(search.value)" placeholder="Search"/>

trigger($event) { switch ($event.name) { case 'gt-info': this.getUserList($event); break; default: console.log($event); break; } }

and my service

searchUsers(searchObject: GtInformation) { return this.http.post(this.config.apiUrl + '/users', searchObject, this.jwt()).map((response: Response) => response.json()); }

It's looping and doesn't stop

What is best way to do this ?

Thanks

image

hjalmers commented 6 years ago

Hi @rullymartanto and sorry for the late reply, perhaps you've solved this already but you're calling this.getUserList($event); on the wrong event. As gt-info will be emitted whenever the table changes it will be triggered again with this.getUserList (my guess is that you update the table using that function right?).

You probably want to call your own function here too:


<input class="form-control form-control-sm mr-sm-2 mb-3 mb-sm-0" #search (keyup)="myTable.gtSearch(search.value)" placeholder="Search"/>

It should probably be:

<input class="form-control form-control-sm mr-sm-2 mb-3 mb-sm-0" #search (keyup)="getUserList(search.value)" placeholder="Search"/>

If your getUserList expects a search string that it will pass on to the server which should then return the new data along with the table info object containing number of pages, search terms etc. You don't need to call myTable.gtSearch(search.value)as the server handles the search when lazy loading.

rullymartanto commented 6 years ago

Well Great Thanks for response I appreciate that