private void AssociatedObject_Sorting(object sender, GridViewSortingEventArgs e) { e.Cancel = true; var sortByPropertyName = (( GridViewDataColumn )e.Column).DataMemberBinding.Path.Path; switch (e.OldSortingState) { case SortingState.None: e.NewSortingState = SortingState.Ascending; SortDirection = ListSortDirection.Ascending; SortBy = sortByPropertyName; break; case SortingState.Ascending: e.NewSortingState = SortingState.Descending; SortDirection = ListSortDirection.Descending; SortBy = sortByPropertyName; break; case SortingState.Descending: SortDirection = ListSortDirection.Ascending; SortBy = sortByPropertyName; break; default: break; } // Sort executed server-side. SortCommand.Execute(null); }
private void OnSorting(object sender, DataGridSortingEventArgs eventArgs) { eventArgs.Handled = true; if (SortCommand != null) { var column = eventArgs.Column; var sortDirection = GetNextSortDirection(column.SortDirection); column.SortDirection = sortDirection; SortCommand.Execute(new SortData(column.Header.ToString(), sortDirection)); } }
private void HeaderCell_OnHeaderTapped(object sender, DataGridColumn dataGridColumn) { if (_currentSortingColumn != dataGridColumn && dataGridColumn.SortingEnabled) { _currentSortingColumn?.ResetOrderType(); _currentSortingColumn = dataGridColumn; } if (_autoSort && _currentSortingColumn != null && _currentSortingColumn.SortingEnabled) { var orderQuery = ItemsSource.AsQueryable().SortBy(_currentSortingColumn.PropertyName, _currentSortingColumn.SortOrderType); SortCommand?.Execute(orderQuery); } HeaderTappedCommand?.Execute(dataGridColumn); }
private void MouseDownOnHeaderCell(object sender, MouseEventArgs args) { var cellClicked = (( FrameworkElement )args.OriginalSource).ParentOfType <GridViewHeaderCell> (); if (cellClicked == null) { return; } var column = ( GridViewDataColumn )cellClicked.Column; var sortByPropertyName = (column).DataMemberBinding.Path.Path; var oldSortDirection = SortDirection; if (sortByPropertyName != SortBy) { oldSortDirection = ListSortDirection.Descending; } switch (oldSortDirection) { case ListSortDirection.Ascending: column.SortingState = SortingState.Descending; SortDirection = ListSortDirection.Descending; SortBy = sortByPropertyName; break; case ListSortDirection.Descending: column.SortingState = SortingState.Ascending; SortDirection = ListSortDirection.Ascending; SortBy = sortByPropertyName; break; default: break; } // Sort executed server-side. SortCommand.Execute(null); }