Improve Filter style

master
Max 4 years ago
parent 6d97cb6ba1
commit 8a9666fb60

@ -48,6 +48,16 @@
> >
nur ungespeicherte Elemente anzeigen nur ungespeicherte Elemente anzeigen
</mat-checkbox> </mat-checkbox>
<button
mat-raised-button
color="primary"
class="table-control-button"
*ngIf="columnFiltersAreSet()"
i18n
(click)="resetColumnFilters()"
>
Spaltenfilterwerte zurücksetzen
</button>
<mat-paginator <mat-paginator
[pageSizeOptions]="[15, 25, 30]" [pageSizeOptions]="[15, 25, 30]"
showFirstLastButtons showFirstLastButtons
@ -73,12 +83,29 @@
[sticky]="isStickyColumn(column.dataPath)" [sticky]="isStickyColumn(column.dataPath)"
><th mat-header-cell *matHeaderCellDef> ><th mat-header-cell *matHeaderCellDef>
<app-filter-row <app-filter-row
*ngIf="filters.columnFilters[column.dataPath]?.isSet"
[column]="column" [column]="column"
[(filter)]="filters.columnFilters[column.dataPath]" [(filter)]="filters.columnFilters[column.dataPath]"
(filtersChange)="newFilterValue()" (filtersChange)="newFilterValue()"
></app-filter-row> ></app-filter-row>
<button
mat-icon-button
matTooltip="Filter hinzufügen"
*ngIf="!filters.columnFilters[column.dataPath]?.isSet"
(click)="
filters.columnFilters[column.dataPath].isSet = true;
setTableFilterRowHeight()
"
>
<mat-icon>filter_list</mat-icon>
</button>
</th> </th>
</ng-container> </ng-container>
<!-- empty filter cell -->
<ng-container matColumnDef="buttons.filter">
<th mat-header-cell *matHeaderCellDef></th>
</ng-container>
<!-- Checkbox Column --> <!-- Checkbox Column -->
<ng-container matColumnDef="select" sticky> <ng-container matColumnDef="select" sticky>
<th mat-header-cell *matHeaderCellDef> <th mat-header-cell *matHeaderCellDef>
@ -327,8 +354,13 @@
<tr <tr
mat-header-row mat-header-row
*matHeaderRowDef="displayedFilterColumns; sticky: true" *matHeaderRowDef="displayedFilterColumns; sticky: true"
class="filter-row"
></tr>
<tr
mat-header-row
*matHeaderRowDef="displayedColumns; sticky: true"
class="header-row"
></tr> ></tr>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr> <tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table> </table>

@ -22,6 +22,7 @@ import { ActivatedRoute } from '@angular/router';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { debounceTime } from 'rxjs/internal/operators/debounceTime'; import { debounceTime } from 'rxjs/internal/operators/debounceTime';
import { SelectObjectDialogComponent } from '../select-object-dialog/select-object-dialog.component'; import { SelectObjectDialogComponent } from '../select-object-dialog/select-object-dialog.component';
import { filter } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-table', selector: 'app-table',
@ -111,16 +112,17 @@ export class TableComponent implements AfterViewInit {
this.columnInfo.forEach((column) => this.columnInfo.forEach((column) =>
this.displayedColumns.push(column.dataPath) this.displayedColumns.push(column.dataPath)
); );
this.displayedColumns.unshift(...this.additionalColumnsFront);
this.displayedColumns.push(...this.additionalColumnsBack);
this.displayedFilterColumns = this.displayedColumns.map( this.displayedFilterColumns = this.displayedColumns.map(
(columnName) => columnName + '.filter' (columnName) => columnName + '.filter'
); );
this.displayedColumns.unshift(...this.additionalColumnsFront);
this.displayedColumns.push(...this.additionalColumnsBack);
this.resetFilters(); this.resetFilters();
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
this.setTableFilterRowHeight();
this.data.paginator = this.paginator; this.data.paginator = this.paginator;
this.data.sortingDataAccessor = (item, columnName) => { this.data.sortingDataAccessor = (item, columnName) => {
if (typeof item[columnName] === 'string') { if (typeof item[columnName] === 'string') {
@ -429,11 +431,20 @@ export class TableComponent implements AfterViewInit {
}); });
} }
resetFilters() { columnFiltersAreSet(): boolean {
this.filters = []; for (const filterObject of Object.keys(this.filters.columnFilters)) {
if (this.filters.columnFilters[filterObject].isSet) {
return true;
}
}
return false;
}
resetColumnFilters() {
this.filters['columnFilters'] = []; this.filters['columnFilters'] = [];
for (const column of this.columnInfo) { for (const column of this.columnInfo) {
this.filters.columnFilters[column.dataPath] = { this.filters.columnFilters[column.dataPath] = {
isSet: false,
value: null, value: null,
minValue: {}, minValue: {},
maxValue: {}, maxValue: {},
@ -444,6 +455,26 @@ export class TableComponent implements AfterViewInit {
options: {}, options: {},
}; };
} }
this.setTableFilterRowHeight();
}
resetFilters() {
this.filters = [];
this.resetColumnFilters();
}
setTableFilterRowHeight() {
setTimeout(() => {
const filterRowHeight = document.getElementsByClassName('filter-row')[0]
.clientHeight;
const headerRowCells = Array.from(
document.getElementsByClassName('header-row')[0]
.children as HTMLCollectionOf<HTMLElement>
);
for (let i = 0; i < headerRowCells.length; i++) {
headerRowCells[i].style.top = filterRowHeight + 'px';
}
});
} }
resetSorting() { resetSorting() {

Loading…
Cancel
Save