Add dateRange filter

master
Max 4 years ago
parent c18706819d
commit 1ee312b070

@ -439,6 +439,8 @@ export class TableComponent implements AfterViewInit {
value: null, value: null,
minValue: {}, minValue: {},
maxValue: {}, maxValue: {},
fromValue: {},
toValue: {},
type: column.type, type: column.type,
options: {}, options: {},
}; };

@ -7,7 +7,7 @@
<mat-form-field class="date-range-input"> <mat-form-field class="date-range-input">
<input <input
matInput matInput
placeholder="Startdatum" [placeholder]="placeholderFrom"
[matDatepicker]="fromPicker" [matDatepicker]="fromPicker"
[value]="stringToDate(from)" [value]="stringToDate(from)"
disabled disabled
@ -31,7 +31,7 @@
<mat-form-field class="date-range-input"> <mat-form-field class="date-range-input">
<input <input
matInput matInput
placeholder="Enddatum" [placeholder]="placeholderFrom"
[matDatepicker]="toPicker" [matDatepicker]="toPicker"
[value]="stringToDate(to)" [value]="stringToDate(to)"
disabled disabled

@ -31,6 +31,12 @@ export class DateRangeCellComponent implements OnInit {
required = false; required = false;
@Input() @Input()
label: string = null; label: string = null;
@Input()
placeholderFrom = "Startdatum";
@Input()
placeholderTo = "Enddatum";
@Output() validityChange = new EventEmitter<boolean>(); @Output() validityChange = new EventEmitter<boolean>();
isValid = true; isValid = true;

@ -90,3 +90,27 @@
(toChange)="newFilterValue()" (toChange)="newFilterValue()"
> >
</app-date-range-cell> </app-date-range-cell>
<!-- DateRange Filter -->
<ng-container *ngIf="column.type === 'DateRange'">
<app-date-range-cell
[editable]="true"
[(from)]="filter.fromValue.from"
(fromChange)="newFilterValue()"
[(to)]="filter.fromValue.to"
(toChange)="newFilterValue()"
placeholderFrom="Startdatum von"
placeholderTo="Startdatum bis"
>
</app-date-range-cell>
<app-date-range-cell
[editable]="true"
[(from)]="filter.toValue.from"
(fromChange)="newFilterValue()"
[(to)]="filter.toValue.to"
(toChange)="newFilterValue()"
placeholderFrom="Enddatum von"
placeholderTo="Enddatum bis"
>
</app-date-range-cell>
</ng-container>

@ -59,30 +59,91 @@ export function customTableFilterFunction(data: any, filter: any) {
if (dataElementMin == null && dataElementMax == null) { if (dataElementMin == null && dataElementMax == null) {
return false; return false;
} }
if (filterElement.minValue.min != null && dataElementMin < filterElement.minValue.min) { if (
filterElement.minValue.min != null &&
dataElementMin < filterElement.minValue.min
) {
return false; return false;
} }
if (filterElement.minValue.max != null && dataElementMin > filterElement.minValue.max) { if (
filterElement.minValue.max != null &&
dataElementMin > filterElement.minValue.max
) {
return false; return false;
} }
if (filterElement.maxValue.min != null && dataElementMax < filterElement.maxValue.min) { if (
filterElement.maxValue.min != null &&
dataElementMax < filterElement.maxValue.min
) {
return false; return false;
} }
if (filterElement.maxValue.max != null && dataElementMax > filterElement.maxValue.max) { if (
filterElement.maxValue.max != null &&
dataElementMax > filterElement.maxValue.max
) {
return false; return false;
} }
} }
} }
// Date Filter // Date Filter
if (filterElement.from != null || filterElement.to != null) { if (
filterElement.type === 'Date' &&
(filterElement.from != null || filterElement.to != null)
) {
let dataElement = data[filterElementName]; let dataElement = data[filterElementName];
if (dataElement == null) { if (dataElement == null) {
return false; return false;
} }
if (filterElement.from != null && new Date(dataElement) < new Date(filterElement.from)) { if (
filterElement.from != null &&
new Date(dataElement) < new Date(filterElement.from)
) {
return false; return false;
} }
if (filterElement.to != null && new Date(dataElement) > new Date(filterElement.to)) { if (
filterElement.to != null &&
new Date(dataElement) > new Date(filterElement.to)
) {
return false;
}
}
// DateRange Filter
if (
filterElement.type === 'DateRange' &&
(filterElement.fromValue.from != null ||
filterElement.fromValue.to != null ||
filterElement.toValue.from != null ||
filterElement.toValue.to != null)
) {
let dataElementFrom = data[filterElementName + '.from'];
let dataElementTo = data[filterElementName + '.to'];
if (!dataElementFrom && !dataElementTo) {
return false;
}
if (
filterElement.fromValue.from != null &&
(!dataElementFrom ||
new Date(dataElementFrom) < new Date(filterElement.fromValue.from))
) {
return false;
}
if (
filterElement.fromValue.to != null &&
new Date(dataElementFrom) > new Date(filterElement.fromValue.to)
) {
return false;
}
if (
filterElement.toValue.from != null &&
new Date(dataElementTo) < new Date(filterElement.toValue.from)
) {
return false;
}
if (
filterElement.toValue.to != null &&
(!dataElementTo ||
new Date(dataElementTo) > new Date(filterElement.toValue.to))
) {
return false; return false;
} }
} }

Loading…
Cancel
Save