@angular/material/sort#MatSortable TypeScript Examples
The following examples show how to use
@angular/material/sort#MatSortable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ng-mat-table-query-reflector.directive.ts From nghacks with MIT License | 6 votes |
private async initialSetup(): Promise<void> {
// HACK 1
await this.waitForQueryParamsToLoad();
const activeSortQuery = this.activeSortQuery;
if (!activeSortQuery) { return; }
const sortable: MatSortable = {
id: activeSortQuery.sort_active,
start: activeSortQuery.sort_direction,
disableClear: true
};
this.dataSource.sort.sort(sortable);
// HACK 2
const activeSortHeader = this.dataSource.sort.sortables.get(activeSortQuery.sort_active);
activeSortHeader['_setAnimationTransitionState']({
fromState: this.dataSource.sort.direction,
toState: 'active',
});
}
Example #2
Source File: ngmat-table-query-reflector.directive.ts From nghacks with MIT License | 6 votes |
private _initialSetup(): void {
const activePageQuery = this.isPageQueryActive();
if (activePageQuery) {
this.dataSource.paginator.pageIndex = activePageQuery.page_index;
this.dataSource.paginator.pageSize = activePageQuery.page_size;
}
// Activating initial Sort
const activeSortQuery = this.isSortQueryActive();
if (activeSortQuery) {
const sortActiveColumn = activeSortQuery ? (activeSortQuery.sort_direction ? activeSortQuery.sort_active : null) : this.matSortActive;
const sortable: MatSortable = {
id: sortActiveColumn,
start: activeSortQuery ? (activeSortQuery.sort_direction || null) : this.matSortDirection,
disableClear: true
};
this.dataSource.sort.sort(sortable);
if (!sortActiveColumn) { return; }
// Material Sort Issue: https://github.com/angular/components/issues/10242
// Picked a hack from: https://github.com/angular/components/issues/10242#issuecomment-421490991
const activeSortHeader = this.dataSource.sort.sortables.get(sortActiveColumn);
if (!activeSortHeader) { return; }
activeSortHeader['_setAnimationTransitionState']({
fromState: this.dataSource.sort.direction,
toState: 'active',
});
}
}
Example #3
Source File: account-struct.component.ts From assetMG with Apache License 2.0 | 6 votes |
sortBySelection() {
if (this.showAdGroupColOnly()) {
this.sort.sort(<MatSortable>{ id: 'adgroup-sel', start: 'desc' });
} else {
this.sort.sort(<MatSortable>{ id: 'desc-sel', start: 'desc' });
this.sort.sort(<MatSortable>{ id: 'headline-sel', start: 'desc' });
}
this.sort.direction = 'desc';
this.dataSource.sort = this.sort;
this.dataSource.sort.sortChange.emit();
}