Add List FIlter

master
Max 4 years ago
parent 61bd7cc266
commit 41af992419

@ -442,6 +442,7 @@ export class TableComponent implements AfterViewInit {
fromValue: {}, fromValue: {},
toValue: {}, toValue: {},
type: column.type, type: column.type,
list: column.list,
options: {}, options: {},
}; };
} }

@ -1,3 +1,15 @@
<!-- List Filter -->
<app-cell
*ngIf="column.list"
[isList]="true"
[editable]="true"
[(value)]="filter.values"
(valueChange)="newFilterValue()"
[inputType]="'String'"
>
</app-cell>
<ng-container *ngIf="!column.list">
<!-- String Filter --> <!-- String Filter -->
<mat-form-field *ngIf="column.type === 'String' || column.type === 'Id'"> <mat-form-field *ngIf="column.type === 'String' || column.type === 'Id'">
<input <input
@ -134,3 +146,4 @@
[inputType]="'Enum//Ja//Nein'" [inputType]="'Enum//Ja//Nein'"
> >
</app-cell> </app-cell>
</ng-container>

@ -7,153 +7,174 @@ 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 // List Filter - ignore types if column is list
if (filterElement.value) { if (filterElement.list && filterElement.values.length > 0) {
if (filterElement.type === 'String' || filterElement.type === 'Id') { let dataElement: Array<any> = data[filterElementName];
let searchString = filterElement.value.trim(); if (dataElement.length !== filterElement.values.length) {
let dataElement = data[filterElementName]?.trim(); return false;
if (dataElement == null) { }
for (const element of filterElement.values) {
if (!dataElement.includes(element)) {
return false; return false;
} }
if (!filterElement.options.caseSensitive) { }
searchString = searchString.toLowerCase(); } else {
dataElement = dataElement.toLowerCase(); // String Filter
if (filterElement.value) {
if (filterElement.type === 'String' || filterElement.type === 'Id') {
let searchString = filterElement.value.trim();
let dataElement = data[filterElementName]?.trim();
if (dataElement == null) {
return false;
}
if (!filterElement.options.caseSensitive) {
searchString = searchString.toLowerCase();
dataElement = dataElement.toLowerCase();
}
if (
(filterElement.options.exact && dataElement !== searchString) ||
!dataElement.includes(searchString)
) {
return false;
}
} }
}
// Number Filter
if (filterElement.min != null || filterElement.max != null) {
if ( if (
(filterElement.options.exact && dataElement !== searchString) || filterElement.type === 'Float' ||
!dataElement.includes(searchString) filterElement.type === 'Int' ||
filterElement.type === 'Money'
) { ) {
return false; let dataElement = data[filterElementName];
if (dataElement == null) {
return false;
}
if (filterElement.min != null && dataElement < filterElement.min) {
return false;
}
if (filterElement.max != null && dataElement > filterElement.max) {
return false;
}
} }
} }
} // NumberRange Filter
// Number Filter if (filterElement.type === 'NumRange') {
if (filterElement.min != null || filterElement.max != null) { if (
filterElement.minValue.min != null ||
filterElement.minValue.max != null ||
filterElement.maxValue.min != null ||
filterElement.maxValue.max != null
) {
let dataElementMin = data[filterElementName + '.min'];
let dataElementMax = data[filterElementName + '.max'];
if (dataElementMin == null && dataElementMax == null) {
return false;
}
if (
filterElement.minValue.min != null &&
dataElementMin < filterElement.minValue.min
) {
return false;
}
if (
filterElement.minValue.max != null &&
dataElementMin > filterElement.minValue.max
) {
return false;
}
if (
filterElement.maxValue.min != null &&
dataElementMax < filterElement.maxValue.min
) {
return false;
}
if (
filterElement.maxValue.max != null &&
dataElementMax > filterElement.maxValue.max
) {
return false;
}
}
}
// Date Filter
if ( if (
filterElement.type === 'Float' || filterElement.type === 'Date' &&
filterElement.type === 'Int' || (filterElement.from != null || filterElement.to != null)
filterElement.type === 'Money'
) { ) {
let dataElement = data[filterElementName]; let dataElement = data[filterElementName];
if (dataElement == null) { if (dataElement == null) {
return false; return false;
} }
if (filterElement.min != null && dataElement < filterElement.min) { if (
filterElement.from != null &&
new Date(dataElement) < new Date(filterElement.from)
) {
return false; return false;
} }
if (filterElement.max != null && dataElement > filterElement.max) { if (
filterElement.to != null &&
new Date(dataElement) > new Date(filterElement.to)
) {
return false; return false;
} }
} }
} // DateRange Filter
// NumberRange Filter
if (filterElement.type === 'NumRange') {
if ( if (
filterElement.minValue.min != null || filterElement.type === 'DateRange' &&
filterElement.minValue.max != null || (filterElement.fromValue.from != null ||
filterElement.maxValue.min != null || filterElement.fromValue.to != null ||
filterElement.maxValue.max != null filterElement.toValue.from != null ||
filterElement.toValue.to != null)
) { ) {
let dataElementMin = data[filterElementName + '.min']; let dataElementFrom = data[filterElementName + '.from'];
let dataElementMax = data[filterElementName + '.max']; let dataElementTo = data[filterElementName + '.to'];
if (dataElementMin == null && dataElementMax == null) { if (!dataElementFrom && !dataElementTo) {
return false; return false;
} }
if ( if (
filterElement.minValue.min != null && filterElement.fromValue.from != null &&
dataElementMin < filterElement.minValue.min (!dataElementFrom ||
new Date(dataElementFrom) < new Date(filterElement.fromValue.from))
) { ) {
return false; return false;
} }
if ( if (
filterElement.minValue.max != null && filterElement.fromValue.to != null &&
dataElementMin > filterElement.minValue.max new Date(dataElementFrom) > new Date(filterElement.fromValue.to)
) { ) {
return false; return false;
} }
if ( if (
filterElement.maxValue.min != null && filterElement.toValue.from != null &&
dataElementMax < filterElement.maxValue.min new Date(dataElementTo) < new Date(filterElement.toValue.from)
) { ) {
return false; return false;
} }
if ( if (
filterElement.maxValue.max != null && filterElement.toValue.to != null &&
dataElementMax > filterElement.maxValue.max (!dataElementTo ||
new Date(dataElementTo) > new Date(filterElement.toValue.to))
) { ) {
return false; return false;
} }
} }
} // Enum Filter
// Date Filter
if (
filterElement.type === 'Date' &&
(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 ( if (
filterElement.to != null && filterElement.type.startsWith('Enum') &&
new Date(dataElement) > new Date(filterElement.to) filterElement.value != null &&
filterElement.value !== data[filterElementName]
) { ) {
return false; return false;
} }
} // Boolean Filter
// 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 ( if (
filterElement.fromValue.from != null && filterElement.type === 'Boolean' &&
(!dataElementFrom || ((filterElement.value === 'Ja' && !data[filterElementName]) ||
new Date(dataElementFrom) < new Date(filterElement.fromValue.from)) (filterElement.value === 'Nein' && data[filterElementName]))
) { ) {
return false; 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;
}
}
// Enum Filter
if (filterElement.type.startsWith('Enum') && filterElement.value != null && filterElement.value !== data[filterElementName]) {
return false;
}
// Boolean Filter
if (filterElement.type === "Boolean" && ((filterElement.value === "Ja" && !data[filterElementName])||(filterElement.value === "Nein" && data[filterElementName]))) {
return false;
} }
} }
/*const b = /*const b =

Loading…
Cancel
Save