Skip to content

Commit 40549d6

Browse files
committed
Add a column search interface to handle search values
This will hold the object keys as properties, and strings as their values. This may not be the best way to implement it, because the interface just has an [index signature][1] for the column names, but it seems to work for now. Hopefully there just get referenced by objectKey. [1]: https://www.typescriptlang.org/docs/handbook/interfaces.html#excess-property-checks
1 parent 225666b commit 40549d6

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

@angular-generic-table/core/components/generic-table.component.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ import { GtEvent } from '../interfaces/gt-event';
4040
[injector]="(gtFields | gtProperty:column.objectKey:'header')?.injector"
4141
[column]="gtFields | gtProperty:column.objectKey:'name'"></gt-custom-component-factory>
4242
<!-- don't trigger a sort when clicking on the search box -->
43-
<input *ngIf="gtSettings | gtProperty:column.objectKey:'searchBox'"
43+
<input #columnSearch *ngIf="gtSettings | gtProperty:column.objectKey:'searchBox'"
4444
(click)="$event.stopPropagation()"
45+
(keyup)="gtColumnSearch(column.objectKey, columnSearch.value)"
4546
type="text"
4647
placeholder="Filter by {{gtFields | gtProperty:column.objectKey:'name' | lowercase}}" />
4748
<gt-checkbox *ngIf="(gtFields | gtProperty:column.objectKey:'columnComponent')?.type === 'checkbox'" [checked]="(selectedRows.length === gtData.length)" (changed)="(selectedRows.length !== gtData.length) ? selectAllRows() : deselectAllRows();"></gt-checkbox>
@@ -252,6 +253,10 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
252253
COLUMNS_WITH_CLASS_NAMES[0].objectKey
253254
);
254255
}
256+
257+
this._gtFields.forEach(field => {
258+
this.gtInfo.columnSearchTerms[field.objectKey] = '';
259+
});
255260
}
256261
@Input()
257262
set gtSettings(value: GtConfigSetting[]) {
@@ -411,7 +416,8 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
411416
recordLength: this.gtOptions.numberOfRows,
412417
recordsAll: 0,
413418
recordsAfterFilter: 0,
414-
recordsAfterSearch: 0
419+
recordsAfterSearch: 0,
420+
columnSearchTerms: {}
415421
};
416422

417423
public refreshPipe = false;
@@ -1236,6 +1242,11 @@ export class GenericTableComponent<R extends GtRow, C extends GtExpandedRow<R>>
12361242
this.updateTotals();
12371243
}
12381244

1245+
public gtColumnSearch(objectKey: number, value: string) {
1246+
// map the column search value to its column
1247+
this.gtInfo.columnSearchTerms[objectKey] = value;
1248+
}
1249+
12391250
/**
12401251
* Add rows
12411252
* @param rows - rows to add
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface GtColumnSearch {
2+
/**
3+
* Column name with its search value.
4+
*/
5+
[columnName: string]: string;
6+
}

@angular-generic-table/core/interfaces/gt-information.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GtColumnSearch } from '../interfaces/gt-column-search';
2+
13
export interface GtInformation {
24
filter?: Object;
35
pageCurrent: number;
@@ -11,5 +13,6 @@ export interface GtInformation {
1113
recordsAfterFilter: number;
1214
recordsAfterSearch: number;
1315
searchTerms?: string;
16+
columnSearchTerms?: GtColumnSearch;
1417
visibleRecords?: any;
1518
}

0 commit comments

Comments
 (0)