ngx-admin icon indicating copy to clipboard operation
ngx-admin copied to clipboard

Error - search customized on smart-table

Open bruno-gds opened this issue 2 years ago • 1 comments

My code following the Documentation:

  • https://akveo.github.io/ng2-smart-table/#/examples/using-filters

component.html:

Smart Table

component.ts:

source: LocalDataSource = new LocalDataSource();

constructor(private httpClient: HttpClient) { this.httpClient.get('/assets/data/Cadastros.json').subscribe((result: Cadastro[]) => { this.data = result; this.source.load(this.data); }); }

filterTable() { if (this.text === ' ') { console.log('Hello'); this.source.load(this.data); } else { this.source.setFilter([ { field: 'Id', search: this.text, }, ], false); } }

My problem is there in the "if" of the function "filter()", I can't update again my table when my search is empty. The documentation is the same, can you help me please.

bruno-gds avatar Jun 08 '22 12:06 bruno-gds

In your code, you are checking if the this.text variable is equal to a single space character (' '). Instead, you should check if it is an empty string ('') to determine if the search is empty.

filterTable() { if (this.text === '') { console.log('Hello'); this.source.load(this.data); } else { this.source.setFilter([ { field: 'Id', search: this.text, }, ], false); } }

Prefix1802 avatar Jul 02 '23 09:07 Prefix1802