private void OnHeaderClicked(TableViewColumnBase column) { if (!column.SortingEnabled) { return; } if (SortedColumn == column) { // If column is already sorted, change the direction SortDirection = SortDirection switch { SortDirection.Ascending => SortDirection.Descending, SortDirection.Descending => SortDirection.None, _ => SortDirection.Ascending }; if (SortDirection == SortDirection.None) { SortedColumn = null; } } else { // Set the column to be sorted by ascending order SortedColumn = column; SortDirection = SortDirection.Ascending; } EnsureItemsAreSorted(); }
private string?GetHeaderClass(TableViewColumnBase column) { return(ClassBuilder.Create("tv-cell-inner", "tv-cell-action", ClassNames.BorderRounded) .AddMultiple(new[] { "sortable", ClassNames.HoverDefault, ClassNames.ActiveDefault }, column.Header != null && column.SortingEnabled) .Add("sorted-" + (SortDirection == SortDirection.Descending ? "desc" : "asc"), column == SortedColumn) .Build()); }
public void RemoveColumn(TableViewColumnBase value) { value.ThrowIfNull(); if (_columnDefinitions.Remove(value)) { value.PropertyChanged -= OnColumnPropertyChanged; ColumnChanged?.Invoke(value, EventArgs.Empty); } }
public void AddColumn(TableViewColumnBase value) { value.ThrowIfNull(); if (!_columnDefinitions.Add(value)) { throw new ApplicationException($"Passed column '{value.GetType().FullName}' was already defined. Ensure each column gets defined only once."); } value.PropertyChanged += OnColumnPropertyChanged; ColumnChanged?.Invoke(value, EventArgs.Empty); }