Skip to content

Commit 9e4979c

Browse files
committed
fix(filtering): apply filtering correctly on dateTime and time columns #7678
1 parent 0909494 commit 9e4979c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

projects/igniteui-angular/src/lib/grids/filtering/excel-style/excel-style-search.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ export class IgxExcelStyleSearchComponent implements AfterViewInit, OnDestroy {
385385
condition: this.createCondition('in'),
386386
fieldName: this.esf.column.field,
387387
ignoreCase: this.esf.column.filteringIgnoreCase,
388-
searchVal: new Set(this.esf.column.dataType === DataType.Date ?
389-
selectedItems.map(d => d.value.toISOString()) :
388+
searchVal: new Set(this.esf.column.dataType === DataType.Date || this.esf.column.dataType === DataType.DateTime ?
389+
selectedItems.map(d => d.value.toISOString()) : this.esf.column.dataType === DataType.Time ?
390+
selectedItems.map(e => e.value.toLocaleTimeString()) :
390391
selectedItems.map(e => e.value))
391392
});
392393

projects/igniteui-angular/src/lib/grids/filtering/excel-style/grid.excel-style-filtering.component.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
498498

499499
for (const expression of this.uniqueValues) {
500500
const value = this.getExpressionValue(expression);
501-
if (this.filterValues.has(this.column.dataType === DataType.DateTime? (value as any).toISOString() : value)) {
501+
if (this.filterValues.has(value)) {
502502
return true;
503503
}
504504
}
@@ -571,13 +571,16 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
571571
private generateUniqueValues(columnValues: any[]) {
572572
if (this.column.dataType === DataType.String && this.column.filteringIgnoreCase) {
573573
const filteredUniqueValues = columnValues.map(s => s?.toString().toLowerCase())
574-
.reduce((map, val, i) => map.get(val) ? map : map.set(val, columnValues[i]),
575-
new Map());
574+
.reduce((map, val, i) => map.get(val) ? map : map.set(val, columnValues[i]), new Map());
576575
this.uniqueValues = Array.from(filteredUniqueValues.values());
577576
} else if (this.column.dataType === DataType.DateTime) {
578577
this.uniqueValues = Array.from(new Set(columnValues.map(v => v.toLocaleString())));
579578
this.uniqueValues.forEach((d, i) => this.uniqueValues[i] = new Date(d));
580-
}else {
579+
} else if (this.column.dataType === DataType.Time) {
580+
this.uniqueValues = Array.from(new Set(columnValues.map(v =>
581+
new Date().setHours(v.getHours(), v.getMinutes(), v.getSeconds()))));
582+
this.uniqueValues.forEach((d, i) => this.uniqueValues[i] = new Date(d));
583+
} else {
581584
this.uniqueValues = this.column.dataType === DataType.Date ?
582585
uniqueDates(columnValues) : Array.from(new Set(columnValues));
583586
}
@@ -592,6 +595,14 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
592595
}
593596
return [ ...arr, ...[e.expression.searchVal ? e.expression.searchVal.toISOString() : e.expression.searchVal] ];
594597
}, []));
598+
} else if (this.column.dataType === DataType.Time) {
599+
this.filterValues = new Set<any>(this.expressionsList.reduce((arr, e) => {
600+
if (e.expression.condition.name === 'in') {
601+
return [ ...arr, ...Array.from((e.expression.searchVal as Set<any>).values()).map(v =>
602+
typeof v === 'string' ? v : new Date(v).toLocaleTimeString()) ];
603+
}
604+
return [ ...arr, ...[e.expression.searchVal ? e.expression.searchVal.toLocaleTimeString() : e.expression.searchVal] ];
605+
}, []));
595606
} else {
596607
this.filterValues = new Set<any>(this.expressionsList.reduce((arr, e) => {
597608
if (e.expression.condition.name === 'in') {
@@ -702,7 +713,7 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
702713

703714
if (shouldUpdateSelection) {
704715
const value = this.getExpressionValue(element);
705-
if (this.filterValues.has(this.column.dataType === DataType.DateTime? (value as any).toISOString() : value)) {
716+
if (this.filterValues.has(value)) {
706717
filterListItem.isSelected = true;
707718
filterListItem.isFiltered = true;
708719
}
@@ -816,6 +827,10 @@ export class IgxGridExcelStyleFilteringComponent implements OnDestroy {
816827
let value;
817828
if (this.column.dataType === DataType.Date) {
818829
value = element && element.value ? new Date(element.value).toISOString() : element.value;
830+
} else if(this.column.dataType === DataType.DateTime) {
831+
value = element ? new Date(element).toISOString() : element;
832+
} else if(this.column.dataType === DataType.Time) {
833+
value = element ? new Date(element).toLocaleTimeString() : element;
819834
} else {
820835
value = element;
821836
}

0 commit comments

Comments
 (0)