Add Date filter

master
Max 4 years ago
parent 233e22b801
commit c18706819d

@ -58,7 +58,7 @@
<!-- NumberRange Filter --> <!-- NumberRange Filter -->
<ng-container *ngIf="column.type === 'NumRange'"> <ng-container *ngIf="column.type === 'NumRange'">
<app-number-range-cell <app-number-range-cell
[editable]="true" [editable]="true"
[(min)]="filter.minValue.min" [(min)]="filter.minValue.min"
(minChange)="newFilterValue()" (minChange)="newFilterValue()"
@ -79,3 +79,14 @@
> >
</app-number-range-cell> </app-number-range-cell>
</ng-container> </ng-container>
<!-- Date Filter -->
<app-date-range-cell
*ngIf="column.type === 'Date'"
[editable]="true"
[(from)]="filter.from"
(fromChange)="newFilterValue()"
[(to)]="filter.to"
(toChange)="newFilterValue()"
>
</app-date-range-cell>

@ -7,6 +7,7 @@ export function customTableFilterFunction(data: any, filter: any) {
} }
for (const filterElementName of Object.keys(filter.columnFilters)) { for (const filterElementName of Object.keys(filter.columnFilters)) {
const filterElement = filter.columnFilters[filterElementName]; const filterElement = filter.columnFilters[filterElementName];
// String Filter
if (filterElement.value) { if (filterElement.value) {
if (filterElement.type === 'String' || filterElement.type === 'Id') { if (filterElement.type === 'String' || filterElement.type === 'Id') {
let searchString = filterElement.value.trim(); let searchString = filterElement.value.trim();
@ -26,6 +27,7 @@ export function customTableFilterFunction(data: any, filter: any) {
} }
} }
} }
// Number Filter
if (filterElement.min != null || filterElement.max != null) { if (filterElement.min != null || filterElement.max != null) {
if ( if (
filterElement.type === 'Float' || filterElement.type === 'Float' ||
@ -44,6 +46,7 @@ export function customTableFilterFunction(data: any, filter: any) {
} }
} }
} }
// NumberRange Filter
if (filterElement.type === 'NumRange') { if (filterElement.type === 'NumRange') {
if ( if (
filterElement.minValue.min != null || filterElement.minValue.min != null ||
@ -70,6 +73,19 @@ export function customTableFilterFunction(data: any, filter: any) {
} }
} }
} }
// Date Filter
if (filterElement.from != null || filterElement.to != null) {
let dataElement = data[filterElementName];
if (dataElement == null) {
return false;
}
if (filterElement.from != null && new Date(dataElement) < new Date(filterElement.from)) {
return false;
}
if (filterElement.to != null && new Date(dataElement) > new Date(filterElement.to)) {
return false;
}
}
} }
/*const b = /*const b =
!filter.includesString || !filter.includesString ||

Loading…
Cancel
Save