public async Task SetNewSortAsync(string sortId, MatSortDirection direction) { SortId = sortId; Direction = direction; await SortIdChanged.InvokeAsync(sortId); await DirectionChanged.InvokeAsync(direction); await SortChanged.InvokeAsync(new MatSortChangedEvent() { SortId = sortId, Direction = direction }); this.StateHasChanged(); }
/// <summary> /// Sort the data by the specified column. /// </summary> /// <param name="column">The column to sort by.</param> /// <remarks>To disable sorting for any given column, set its Sortable property set to false.</remarks> protected async Task SortByAsync(PDColumn <TItem> column, SortDirection?direction = null) { if (column.Sortable && !string.IsNullOrWhiteSpace(column.Id)) { // if direction specified then sort as requested if (direction.HasValue) { column.SortDirection = direction.Value; } else { // if column already sorted then reverse direction if (column.Id == SortCriteria?.Key) { column.SortDirection = column.SortDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending; } else { var previousCol = Columns.Find(x => x.Id == SortCriteria?.Key); if (previousCol != null) { previousCol.SortDirection = SortDirection.None; } column.SortDirection = SortDirection.Ascending; } } if (SortCriteria != null) { SortCriteria.Key = column.Id; SortCriteria.Direction = column.SortDirection; } await GetDataAsync().ConfigureAwait(true); await SortChanged.InvokeAsync(new SortCriteria { Key = column.Id, Direction = direction ?? column.SortDirection }).ConfigureAwait(true); } }