<input class="form-control"
type="text"
[(ngModel)]="search"
- (keyup)="updateFilter($event)">
+ (keyup)="updateFilter()">
<span class="input-group-btn">
<button type="button"
class="btn btn-default clear-input tc_clearInputBtn"
- (click)="updateFilter()">
+ (click)="updateFilter(true)">
<i class="icon-prepend fa fa-remove"></i>
</button>
</span>
describe('test search', () => {
const doSearch = (search: string, expectedLength: number, firstObject: object) => {
component.search = search;
- component.updateFilter(true);
+ component.updateFilter();
expect(component.rows.length).toBe(expectedLength);
expect(component.rows[0]).toEqual(firstObject);
};
const searchTest = (s: string, st: string[]) => {
component.search = s;
searchTerms = st;
- component.updateFilter(true);
+ component.updateFilter();
};
searchTest('a b c', ['a', 'b', 'c']);
searchTest('a+b c', ['a+b', 'c']);
it('should restore full table after search', () => {
expect(component.rows.length).toBe(100);
component.search = '13';
- component.updateFilter(true);
- expect(component.rows.length).toBe(9);
component.updateFilter();
+ expect(component.rows.length).toBe(9);
+ component.updateFilter(true);
expect(component.rows.length).toBe(100);
});
});
}
this.rows = [...this.data];
if (this.search.length > 0) {
- this.updateFilter(true);
+ this.updateFilter();
}
this.reset();
this.updateSelected();
this.userConfig.sorts = sorts;
}
- updateFilter(event?: any) {
- if (!event) {
+ updateFilter(clearSearch = false) {
+ if (clearSearch) {
this.search = '';
}
+ // prepare search strings
let search = this.search.toLowerCase().replace(/,/g, '');
const columns = this.columns.filter((c) => c.cellTransformation !== CellTemplate.sparkline);
if (search.match(/['"][^'"]+['"]/)) {
return this.subSearch(data, currentSearch, columnsClone);
}
- basicDataSearch(searchTerm: string, data: any[], columns: CdTableColumn[]) {
+ basicDataSearch(searchTerm: string, rows: any[], columns: CdTableColumn[]) {
if (searchTerm.length === 0) {
- return data;
+ return rows;
}
- return data.filter((d) => {
+ return rows.filter((row) => {
return (
- columns.filter((c) => {
- let cellValue: any = _.get(d, c.prop);
- if (!_.isUndefined(c.pipe)) {
- cellValue = c.pipe.transform(cellValue);
+ columns.filter((col) => {
+ let cellValue: any = _.get(row, col.prop);
+
+ if (!_.isUndefined(col.pipe)) {
+ cellValue = col.pipe.transform(cellValue);
}
if (_.isUndefined(cellValue)) {
return;
}
+
if (_.isArray(cellValue)) {
cellValue = cellValue.join(' ');
} else if (_.isNumber(cellValue) || _.isBoolean(cellValue)) {