});
}
private previousRows = new Map<string | number, TableItem[]>();
+ private debouncedSearch = this.reloadData.bind(this);
constructor(
// private ngZone: NgZone,
// debounce reloadData method so that search doesn't run api requests
// for every keystroke
if (this.serverSide) {
- this.reloadData = _.debounce(this.reloadData, 1000);
+ this.reloadData = _.throttle(this.reloadData.bind(this), 1000, {
+ leading: true,
+ trailing: false
+ });
+ this.debouncedSearch = _.debounce(this.reloadData.bind(this), 1000);
+ } else {
+ this.debouncedSearch = this.reloadData.bind(this);
}
// ngx-datatable triggers calculations each time mouse enters a row,
});
context.pageInfo.offset = this.userConfig.offset;
context.pageInfo.limit = this.userConfig.limit;
- context.search = this.userConfig.search;
+ if (this.serverSide) context.search = this.search;
+ else context.search = this.userConfig.search;
if (this.userConfig.sorts?.length) {
const sort = this.userConfig.sorts[0];
context.sort = `${sort.dir === 'desc' ? '-' : '+'}${sort.prop}`;
this.userConfig.limit = this.limit;
this.userConfig.search = this.search;
this.updating = false;
- this.reloadData();
+ this.debouncedSearch();
}
this.rows = this.data;
} else {