@angular/material/sort#Sort TypeScript Examples
The following examples show how to use
@angular/material/sort#Sort.
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: basic-sort-header.component.ts From matx-angular with MIT License | 6 votes |
sortData(sort: Sort) {
const data = this.desserts.slice();
if (!sort.active || sort.direction === '') {
this.sortedData = data;
return;
}
this.sortedData = data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'name': return compare(a.name, b.name, isAsc);
case 'calories': return compare(a.calories, b.calories, isAsc);
case 'fat': return compare(a.fat, b.fat, isAsc);
case 'carbs': return compare(a.carbs, b.carbs, isAsc);
case 'protein': return compare(a.protein, b.protein, isAsc);
default: return 0;
}
});
}
Example #2
Source File: ng-mat-table-query-reflector.directive.ts From nghacks with MIT License | 6 votes |
private _applySortChangesToUrlQueryParams(sortChange: Sort): void {
const sortingAndPaginationQueryParams = {
sort_active: sortChange.active,
sort_direction: sortChange.direction,
};
this._router.navigate([], {
queryParams: sortingAndPaginationQueryParams,
queryParamsHandling: 'merge'
});
}
Example #3
Source File: ngmat-table-query-reflector.directive.ts From nghacks with MIT License | 6 votes |
private listenToStateChangeEvents(): void {
this.dataSource.sort.sortChange
.pipe(
takeUntil(this.unsubscribeAll$)
)
.subscribe((sortChange: Sort) => {
this._applySortChangesToUrlQueryParams(sortChange);
});
this.dataSource.paginator.page
.pipe(
takeUntil(this.unsubscribeAll$)
)
.subscribe((pageChange: PageEvent) => {
this._applyPageStateChangesToUrlQueryParams(pageChange);
});
}
Example #4
Source File: ngmat-table-query-reflector.directive.ts From nghacks with MIT License | 6 votes |
private _applySortChangesToUrlQueryParams(sortChange: Sort): void {
const sortingAndPaginationQueryParams = {
sort_active: sortChange.active,
sort_direction: sortChange.direction,
};
this._router.navigate([], { queryParams: sortingAndPaginationQueryParams, queryParamsHandling: 'merge' });
}
Example #5
Source File: genes-methylation-list.component.ts From open-genes-frontend with Mozilla Public License 2.0 | 6 votes |
sortData(sort: Sort) {
const data = this.searchedData.slice();
if (!sort.active || sort.direction === '') {
this.searchedData = data;
return;
}
this.searchedData = data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'symbol':
return this.compare(a.symbol, b.symbol, isAsc);
case 'correlation':
return this.compare(a.methylationCorrelation, b.methylationCorrelation, isAsc);
default:
return 0;
}
});
}
Example #6
Source File: diet-table.component.ts From open-genes-frontend with Mozilla Public License 2.0 | 6 votes |
public sortData(sort: Sort): void {
const data = this.genesList.slice();
if (!sort.active || sort.direction === '') {
this.genesList = data;
return;
}
this.genesList = data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'name':
return this.compare(a.name, b.name, isAsc);
default:
return 0;
}
});
}
Example #7
Source File: orders.component.ts From material-reusable-table with Apache License 2.0 | 6 votes |
sortData(sortParameters: Sort) {
const keyName = sortParameters.active;
if (sortParameters.direction === 'asc') {
this.orders = this.orders.sort((a: Order, b: Order) => a[keyName].localeCompare(b[keyName]));
} else if (sortParameters.direction === 'desc') {
this.orders = this.orders.sort((a: Order, b: Order) => b[keyName].localeCompare(a[keyName]));
} else {
return this.orders = this.getOrders();
}
}
Example #8
Source File: champion-purchase-date.component.ts From league-profile-tool with MIT License | 6 votes |
public sortData(sort: Sort) {
const data = this.championData.slice();
if (!sort.active || sort.direction === '') {
this.sortedData = data;
return;
}
this.sortedData = data.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case 'name':
return compare(a.name.toLowerCase(), b.name.toLowerCase(), isAsc);
case 'purchased':
return compare(a.purchasedHidden, b.purchasedHidden, isAsc);
default:
return 0;
}
});
}
Example #9
Source File: genes-list.component.ts From open-genes-frontend with Mozilla Public License 2.0 | 6 votes |
/**
* Sorting genes list
*/
public sortBy(sort: Sort): void {
const unSortedData = this.searchedData.slice();
if (sort.active !== this.sortEnum.byCriteriaQuantity) {
if (!sort.active || sort.direction === '') {
this.searchedData = this.cachedData;
return;
}
this.searchedData = unSortedData.sort((a, b) => {
const isAsc = sort.direction === 'asc';
switch (sort.active) {
case this.sortEnum.byName:
return this.compare((a.symbol + a.name).toLowerCase(), (b.symbol + b.name).toLowerCase(), isAsc);
case this.sortEnum.byAge:
return this.compare(a.familyOrigin?.order, b.familyOrigin?.order, isAsc);
default:
return 0;
}
});
} else {
this.filterService.sortParams = sort;
this.isLoading = true;
this.searchedData = [];
this.filterService
.getSortedAndFilteredGenes()
.subscribe((sortedGenes) => {
this.searchedData = sortedGenes.items;
this.isLoading = false;
this.cdRef.markForCheck();
});
}
}
Example #10
Source File: table.component.ts From material-reusable-table with Apache License 2.0 | 5 votes |
sortTable(sortParameters: Sort) {
// defining name of data property, to sort by, instead of column name
sortParameters.active = this.tableColumns.find(column => column.name === sortParameters.active).dataKey;
this.sort.emit(sortParameters);
}
Example #11
Source File: filter.service.ts From open-genes-frontend with Mozilla Public License 2.0 | 5 votes |
public sortParams: Sort;
Example #12
Source File: filter-panel.component.ts From open-genes-frontend with Mozilla Public License 2.0 | 5 votes |
@Output() sortItem: EventEmitter<Sort> = new EventEmitter<Sort>();
Example #13
Source File: filter-panel.component.ts From open-genes-frontend with Mozilla Public License 2.0 | 5 votes |
/**
* Send sort item
*/
public sortBy(event: Sort) {
this.sortItem.emit(event);
}
Example #14
Source File: table.component.ts From material-reusable-table with Apache License 2.0 | 5 votes |
@Output() sort: EventEmitter<Sort> = new EventEmitter();
Example #15
Source File: ranking.component.ts From oss-github-benchmark with GNU General Public License v3.0 | 5 votes |
sortState: Sort = { active: 'num_repos', direction: 'desc' }
Example #16
Source File: explore-item.component.ts From oss-github-benchmark with GNU General Public License v3.0 | 5 votes |
sortState: Sort = { active: 'name', direction: 'desc' }
Example #17
Source File: ng-mat-table-query-reflector.directive.ts From nghacks with MIT License | 5 votes |
private listenToStateChangeEvents(): void {
this.dataSource.sort.sortChange.subscribe((sortChange: Sort) => {
this._applySortChangesToUrlQueryParams(sortChange);
});
}