param table default sorting
This commit is contained in:
parent
0da6daaa85
commit
602793d2a4
@ -64,14 +64,28 @@ export class ParamTableComponent {
|
|||||||
|
|
||||||
@ViewChild(MatSort, { static: false })
|
@ViewChild(MatSort, { static: false })
|
||||||
set sort(value: MatSort) {
|
set sort(value: MatSort) {
|
||||||
this.dataSource.sort = value;
|
if (value) {
|
||||||
|
// 1. Assign the sort object to the data source immediately
|
||||||
|
this.dataSource.sort = value;
|
||||||
|
|
||||||
|
// 2. Apply default settings inside a timeout to avoid the NG0100 error
|
||||||
|
setTimeout(() => {
|
||||||
|
if (this.table_mode === 'TABLE-RECORD' && !value.active) {
|
||||||
|
// Only set default if a sort isn't already active
|
||||||
|
value.active = 'paramValue';
|
||||||
|
value.direction = 'asc';
|
||||||
|
|
||||||
|
// 3. Instead of emitting an event, manually trigger the sort logic
|
||||||
|
// through the DataSource's internal sortingDataAccessor
|
||||||
|
this.dataSource.sort = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paramForm: FormGroup;
|
paramForm: FormGroup;
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
this.dataSource.paginator = this.paginator;
|
|
||||||
this.dataSource.sort = this.sort;
|
|
||||||
this.dataSource.data = this.paramData;
|
this.dataSource.data = this.paramData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user