public void HandleSorting(IItem selectedItem, ListSortDirection? sortDirection = null) { var allColumns = _lister.Columns.Where(co => !string.IsNullOrEmpty(co.Header)).ToDictionary(co => co.Header, co => co.BindingExpression); var items = _lister.View?.ListView.Items; if (items == null) //Lister closed return; var currentSort = items.SortDescriptions.FirstOrDefault(); var newSort = allColumns[selectedItem.DisplayName]; var direction = sortDirection ?? ListSortDirection.Ascending; if (currentSort.PropertyName == newSort) direction = currentSort.Direction == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; using (items.DeferRefresh()) { items.SortDescriptions.Clear(); var sortDescription = new SortDescription(newSort, direction); items.SortDescriptions.Add(sortDescription); } if (_lister.View.ListView.View is GridView gridView) { var headers = gridView.Columns.Select(c => c.Header as GridViewColumnHeader).Where(c => c?.Content != null).ToDictionary(c => c.Content as string, c => c); var header = headers[selectedItem.Path]; UpdateSortAdorner(header, direction, _lister); } }
private void Sort(string column, ListSortDirection?direction) { if (column == "Version") { // we can't sort Version return; } if (SortColumn == column) { if (direction.HasValue) { SortDirection = direction.Value; } else { SortDirection = SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; } } else { SortColumn = column; SortDirection = direction ?? ListSortDirection.Ascending; } // trigger the dialog to update Sort glyph SortCounter++; LoadPackages(); }
private void lvDownload_HeaderClick(object sender, RoutedEventArgs e) { ListSortDirection?direction = ListSortDirection.Ascending; var headerClicked = e.OriginalSource as GridViewColumnHeader; if (headerClicked == null || headerClicked.Role == GridViewColumnHeaderRole.Padding) { return; } if (headerClicked == _lastHeaderClicked) { if (_lastDirection == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; } else if (_lastDirection == ListSortDirection.Descending) { direction = null; } else { direction = ListSortDirection.Ascending; } } Sort(headerClicked, direction); }
private void chName_Click(object sender, RoutedEventArgs e) { if (_dir == ListSortDirection.Ascending) { _dir = ListSortDirection.Descending; } else if (_dir == ListSortDirection.Descending) { _dir = null; } else if (_dir == null) { _dir = ListSortDirection.Ascending; } ICollectionView dataView = CollectionViewSource.GetDefaultView(lvKeyValue.ItemsSource); dataView.SortDescriptions.Clear(); if (_dir.HasValue) { SortDescription sd = new SortDescription("Name", _dir.Value); dataView.SortDescriptions.Add(sd); dataView.Refresh(); } }
/// <summary> /// Retourne une liste chargée en mémoire. /// </summary> public async Task <IEnumerable <T> > GetListAsync <T, TKey>( Expression <Func <T, bool> > iWhere = null, List <Expression <Func <T, object> > > iNavigationProperties = null, Expression <Func <T, TKey> > iOrderByProperty = null, ListSortDirection?iSortDirection = null, int?iSkip = null, int?iTake = null) where T : class, IEntity { Func <Task <IEnumerable <T> > > theTask = async() => { if (iOrderByProperty != null && iSortDirection == null) { throw new ArgumentNullException(); } if (iTake != null && iOrderByProperty == null) { throw new ArgumentNullException(); } if (iSkip != null && iOrderByProperty == null) { throw new ArgumentNullException(); } return(await Task.Run(() => GetQuery <T, TKey>(iWhere, iNavigationProperties, iOrderByProperty, iSortDirection, iSkip, iTake))); }; return(await RetryExecution(theTask)); }
private void Sort(GridViewColumnHeader columnHeader, ListSortDirection?direction) { if (_dataView == null) { _dataView = CollectionViewSource.GetDefaultView(lvDownload.ItemsSource); } _dataView.SortDescriptions.Clear(); if (direction == null) { return; } var columnBinding = columnHeader.Column.DisplayMemberBinding as Binding; var sortBy = columnBinding?.Path.Path ?? columnHeader.Column.Header as string; switch (sortBy.ToLower()) { case null: return; case "downloaded": sortBy = "TotalBytesCompleted"; break; case "size": sortBy = "TotalBytesToDownload"; break; case "location": sortBy = "Destination"; break; case "url": sortBy = "Url"; break; case "created": sortBy = "DateCreated"; break; case "http status": sortBy = "StatusCode"; break; case "eta": sortBy = "TimeRemaining"; break; case "type": sortBy = "Extension"; break; case "connections": sortBy = "NumberOfActiveStreams"; break; } SortDescription sd = new SortDescription(sortBy, direction ?? ListSortDirection.Ascending); _dataView.SortDescriptions.Add(sd); }
public void Sort(PropertyInfo SortProperty, ListSortDirection?SortDirection) { // Set the modification flag Modification = true; IEnumerable <TreeGridElement> RootNodes = this.Where(element => element.Parent == null).ToList(); Items.Clear(); if (SortDirection == ListSortDirection.Ascending) { RootNodes = RootNodes.OrderBy(n => SortProperty.GetValue(n)); } else { RootNodes = RootNodes.OrderByDescending(n => SortProperty.GetValue(n)); } CurrentSortDirection = SortDirection; CurrentSortProperty = SortProperty; foreach (TreeGridElement Node in RootNodes.ToList()) { SortNodes(Node); } OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); // Clear the modification flag Modification = false; }
public static string FormSqlGrid(int columnNumber, ListSortDirection?direction, Dictionary <int, string> filters, Dictionary <int, string> sortsource, string gridPart1, string gridPart2) { string result = gridPart1; result += sortsource[columnNumber]; if (direction.HasValue) { if (direction == ListSortDirection.Ascending) { result += " asc "; } else { result += " desc "; } } else { result += " asc "; } result += gridPart2; string filter = ""; foreach (var item in filters) { if (item.Value != "") { filter += @" and " + item.Value; } } result = result.Replace("1 = 1", "1 = 1" + filter); return(result); }
private static void UpdateHeader(GridViewColumnHeader header, ListSortDirection?direction) { // Set the sort direction on the header SetSortDirection(header, direction); // Find the property to report to the command string property = GetSortProperty(header.Column); if (property == null) { if (header.Content is string) { property = header.Content as string; } else { throw new InvalidOperationException("No sort property or string header defined on column"); } } SortArgument sort_argument = new SortArgument(property, direction); // Execute the command ICommand command = GetSortCommand(header.Column) as ICommand; if (command != null && command.CanExecute(sort_argument)) { command.Execute(sort_argument); } }
public override void ReadXml(XmlReader r) { if (r.IsEmptyElement) { return; } while (r.Read() && !r.EOF && r.NodeType != XmlNodeType.EndElement) { if (r.NodeType == XmlNodeType.Element) { switch (r.Name) { case "SelectedSecurity": this.SelectedSecurity = r.ReadString(); break; case "SortedColumn": this.SortedColumn = ReadInt(r, -1); break; case "SortDirection": this.SortDirection = ReadEnum <ListSortDirection>(r); break; } } } }
public ColumnInformation(DataGridColumn column) { Header = column.Header; if (!(column is DataGridTemplateColumn)) { if (column is DataGridComboBoxColumn) { PropertyPath = column.SortMemberPath; } else { PropertyPath = ((Binding)((DataGridBoundColumn)column).Binding).Path.Path; } } else { PropertyPath = column.SortMemberPath; } WidthValue = column.Width.DisplayValue; WidthType = column.Width.UnitType; SortDirection = column.SortDirection; DisplayIndex = column.DisplayIndex; SortMemberPath = column.SortMemberPath; IsVisible = column.IsVisible; }
public ColumnSpec SetSortDirection(ListSortDirection?value) { return(new ColumnSpec(this) { SortDirection = value }); }
public GridSortableHeaderCellBuilder(IDictionary<string, object> htmlAttributes, string url, ListSortDirection? sortDirection, string sortedAscText, string sortedDescText, Action<IHtmlNode> appendContent) : base(htmlAttributes, appendContent) { this.sortDirection = sortDirection; this.sortedAscText = sortedAscText; this.sortedDescText = sortedDescText; this.url = url; }
public GridSortableHeaderCellBuilder(IDictionary <string, object> htmlAttributes, string url, ListSortDirection?sortDirection, string sortedAscText, string sortedDescText, Action <IHtmlNode> appendContent) : base(htmlAttributes, appendContent) { this.sortDirection = sortDirection; this.sortedAscText = sortedAscText; this.sortedDescText = sortedDescText; this.url = url; }
/// <summary> /// Sets the sort direction. /// </summary> /// <param name="obj">The object.</param> /// <param name="value">The value.</param> /// <exception cref="System.ArgumentNullException">obj</exception> public static void SetSortDirection(DependencyObject obj, ListSortDirection?value) { if (obj == null) { throw new ArgumentNullException("obj"); } obj.SetValue(SortDirectionProperty, value); }
static string SortString(ListSortDirection?sort) { return(sort.HasValue ? sort.Value == ListSortDirection.Ascending ? "asc" : "desc" : default(string)); }
private void SetSorting(GridViewColumnHeader columnHeader, ListSortDirection?sortingDirection = null) { if (!this.IsSortable) { return; } var path = GridViewColumnProperties.GetSortingPropertyName(columnHeader); if (path == null) { return; } var gridView = columnHeader.Column.GetInheritanceContext() as GridView; if (gridView == null) { return; } var listView = gridView.GetInheritanceContext() as ListView; if (listView == null) { return; } if (this.sortedHeader != null) { AdornerLayer.GetAdornerLayer(this.sortedHeader).Remove(this.sortAdorner); listView.Items.SortDescriptions.Clear(); } var newSorting = sortingDirection ?? ListSortDirection.Ascending; if (!sortingDirection.HasValue && this.sortedHeader == columnHeader && this.sortAdorner.Direction == newSorting) { newSorting = ListSortDirection.Descending; } this.sortedHeader = columnHeader; this.sortAdorner = new SortAdorner(this.sortedHeader, newSorting) { Foreground = this.InheritanceContext.As <ListView>()?.Foreground }; AdornerLayer.GetAdornerLayer(this.sortedHeader).Add(this.sortAdorner); try { listView.Items.SortDescriptions.Add(new SortDescription(path, newSorting)); } catch (Exception e) { Debug.WriteLine("Error: Unable to sort elements: " + e.Message); } }
public void updateUserList(DataManager.Server obj) { this.Dispatcher.Invoke((Action)(() => { //if (userList.Items.Count != 0) //{ string dgSortDescriptionUser = null; ListSortDirection?dgSortDirectionUser = null; int columnIndexUser = 0; //System.Collections.ObjectModel.ObservableCollection<DataGrid> itemsColl = null; foreach (DataGridColumn column in userList.Columns) { columnIndexUser++; if (column.SortDirection != null) { dgSortDirectionUser = column.SortDirection; dgSortDescriptionUser = column.SortMemberPath; break; } } try { userList.ItemsSource = obj.playersList; } catch (Exception err) { Console.WriteLine(err.Message); } if (!string.IsNullOrEmpty(dgSortDescriptionUser) && dgSortDirectionUser != null) { SortDescription sUser = new SortDescription(dgSortDescriptionUser, dgSortDirectionUser.Value); CollectionView viewUser = (CollectionView)CollectionViewSource.GetDefaultView(userList.ItemsSource); try { viewUser.SortDescriptions.Add(sUser); userList.Columns[columnIndexUser - 1].SortDirection = dgSortDirectionUser; } catch (Exception err) { //Console.WriteLine(err.Message); //DataManager.Server currentServer = dm.getCurrentServerList(); //selectedIP = currentServer.IP_Address; //updateUserList(dm.userList(selectedIP)); } } })); //} //else //{ // userList.ItemsSource = obj.linkItem; //} }
public ColumnInfo(DataGridColumn column) { Header = column.Header; PropertyPath = ((Binding)((DataGridBoundColumn)column).Binding).Path.Path; WidthValue = column.Width.DisplayValue; WidthType = column.Width.UnitType; SortDirection = column.SortDirection; DisplayIndex = column.DisplayIndex; }
public static void SetSortDirection(UIElement element, ListSortDirection?value) { if (element == null) { throw new ArgumentNullException("element"); } element.SetValue(SortDirectionProperty, value); }
void ResourceColumnSorting(object sender, SortingCancellableEventArgs e) { if (_previousResourceDirection == null) { _previousResourceDirection = ListSortDirection.Ascending; } Sort(sender, e); }
private void SetSortDirection(string sortMemberPath, ListSortDirection?direction) { var column = AssociatedObject.Columns.FirstOrDefault(c => c.SortMemberPath == sortMemberPath); if (column != null) { column.SortDirection = direction; } }
public string GetSortUrl() { IList <SortDescriptor> orderBy = new List <SortDescriptor>(Grid.DataSource.OrderBy); SortDescriptor descriptor = orderBy.SingleOrDefault(c => c.Member.IsCaseInsensitiveEqual(Member)); ListSortDirection?oldDirection = null; if (descriptor != null) { oldDirection = descriptor.SortDirection; ListSortDirection?newDirection = oldDirection.Next(); if (newDirection == null) { if (!Grid.Sortable.AllowUnsort) { newDirection = ListSortDirection.Ascending; } else { orderBy.Remove(descriptor); } } if (newDirection != null) { if (Grid.Sortable.SortMode == GridSortMode.SingleColumn) { orderBy.Clear(); orderBy.Add(new SortDescriptor { SortDirection = newDirection.Value, Member = descriptor.Member }); } else { orderBy[orderBy.IndexOf(descriptor)] = new SortDescriptor { SortDirection = newDirection.Value, Member = descriptor.Member }; } } } else { if (Grid.Sortable.SortMode == GridSortMode.SingleColumn) { orderBy.Clear(); } orderBy.Add(new SortDescriptor { Member = Member, SortDirection = ListSortDirection.Ascending }); } return(Grid.UrlBuilder.SelectUrl(GridUrlParameters.Sort, GridDescriptorSerializer.Serialize(orderBy))); }
public void SetDefaultSort(DataGridColumn col, ListSortDirection?sortDirection) { defaultSortColumn = col; defaultSortDirection = sortDirection ?? ListSortDirection.Ascending; if (defaultSortColumn != null) { ClearColumnSortDirections(); defaultSortColumn.SortDirection = defaultSortDirection; } }
public DataGridLengthUnitType WidthType; // Width type (Pixel, Star, Auto...) public ColumnInfo(DataGridColumn column) { Header = column.Header; PropertyPath = column.SortMemberPath; WidthValue = column.Width.DisplayValue; WidthType = column.Width.UnitType; Visibility = column.Visibility; SortDirection = column.SortDirection; DisplayIndex = column.DisplayIndex; }
/// <summary> /// ConverterComparer constructor /// </summary> /// <param name="converter">Converter to use to convert the objects before comparing them</param> /// <param name="direction">Sort direction for the comparison; defaults to Ascending</param> /// <param name="parameter">Parameter that will be passed to the converter</param> /// <param name="targetType">Target type that will be passed to the converter; defaults to typeof(string)</param> /// <param name="cultureInfo">Cultural info to pass to converter; defaults to CurrentThread.CurrentCulture</param> public ConverterComparer([NotNull] IValueConverter converter, ListSortDirection?direction, [CanBeNull] object parameter, Type targetType = null, CultureInfo cultureInfo = null) { _converter = converter; _direction = direction ?? ListSortDirection.Ascending; _parameter = parameter; _targetType = targetType ?? typeof(string); _cultureInfo = cultureInfo ?? System.Threading.Thread.CurrentThread.CurrentCulture; }
private void GotoVisualState(bool useTransitions, ListSortDirection?direction) { var stateName = direction.HasValue ? (direction.Value == System.ComponentModel.ListSortDirection.Ascending ? AscendingStateName : DescendingStateName) : NoneStateName; VisualStateManager.GoToState(this, stateName, useTransitions); }
/// <summary> /// Recupera a próximo direção de ordenação. /// </summary> /// <param name="sortDirection"></param> /// <returns></returns> private static ListSortDirection GetNextSortDirection(ListSortDirection?sortDirection) { ListSortDirection valueOrDefault = sortDirection.GetValueOrDefault(); if (sortDirection.HasValue && (valueOrDefault == ListSortDirection.Ascending)) { return(ListSortDirection.Descending); } return(ListSortDirection.Ascending); }
private void lvDownload_HeaderClick(object sender, RoutedEventArgs e) { ListSortDirection?direction = ListSortDirection.Ascending; var headerClicked = e.OriginalSource as GridViewColumnHeader; if (headerClicked != null) { if (headerClicked.Role != GridViewColumnHeaderRole.Padding) { if (headerClicked == _lastHeaderClicked) { if (_lastDirection == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; } else if (_lastDirection == ListSortDirection.Descending) { direction = null; } else { direction = ListSortDirection.Ascending; } } Sort(headerClicked, direction); if (_lastHeaderClicked != null) { _lastHeaderClicked.Column.HeaderTemplate = Resources["HeaderTemplate"] as DataTemplate; } if (direction == ListSortDirection.Ascending) { headerClicked.Column.HeaderTemplate = Resources["HeaderTemplateArrowDown"] as DataTemplate; } else if (direction == ListSortDirection.Descending) { headerClicked.Column.HeaderTemplate = Resources["HeaderTemplateArrowUp"] as DataTemplate; } else { headerClicked.Column.HeaderTemplate = Resources["HeaderTemplate"] as DataTemplate; } _dataView.Refresh(); _lastHeaderClicked = headerClicked; _lastDirection = direction; } } }
private static ListSortDirection GetNextSortDirection(ListSortDirection?sortDirection) { switch (sortDirection) { case ListSortDirection.Ascending: return(ListSortDirection.Descending); default: return(ListSortDirection.Ascending); } }
public ListSortDirection?ToggleSortDirection(ListSortDirection?sortDirection) { if (sortDirection == ListSortDirection.Ascending) { return(ListSortDirection.Descending); } else { return(ListSortDirection.Ascending); } }
protected void Order() { if (this.CanOrder) { var currentDirection = CurrentDirection == null ? ListSortDirection.Ascending : (CurrentDirection == ListSortDirection.Descending ? ListSortDirection.Ascending : ListSortDirection.Descending); this.CurrentDirection = currentDirection; this.Parent.Order(this.OrderingExpression, currentDirection, this.Index); } }
// Get the current sort column from XAML or sort using the first column of the Grid. protected override void OnInitialized(EventArgs e) { base.OnInitialized(e); // The current sorted column must be specified in XAML. _currentSortColumn = Columns.FirstOrDefault(c => c.SortDirection.HasValue); // if not, then take the first column of the grid and set the sort direction to ascending if (_currentSortColumn == null) { _currentSortColumn = Columns.First(); _currentSortColumn.SortDirection = ListSortDirection.Ascending; } _currentSortDirection = _currentSortColumn.SortDirection; }
/// <summary> /// Sortuje dane i przechodzi do pierwszej strony /// </summary> /// <param name="e"></param> public void Sort(DataGridSortingEventArgs e) { // has to be done manually, SortDirection is set to null every time ItemsSource changes if (SortDirection == ListSortDirection.Descending || e.Column.SortMemberPath != SortProperty) { SortDirection = ListSortDirection.Ascending; } else { SortDirection = ListSortDirection.Descending; } SortProperty = e.Column.SortMemberPath; CurrentPage = 1; e.Handled = true; UpdateData(); }
private void chName_Click(object sender, RoutedEventArgs e) { if (_dir == ListSortDirection.Ascending) _dir = ListSortDirection.Descending; else if (_dir == ListSortDirection.Descending) _dir = null; else if (_dir == null) _dir = ListSortDirection.Ascending; ICollectionView dataView = CollectionViewSource.GetDefaultView(lvKeyValue.ItemsSource); dataView.SortDescriptions.Clear(); if (_dir.HasValue) { SortDescription sd = new SortDescription("Name", _dir.Value); dataView.SortDescriptions.Add(sd); dataView.Refresh(); } }
// Deactivate the default Grid sorting, call the ISortbleSorting protected override void OnSorting(DataGridSortingEventArgs eventArgs) { eventArgs.Handled = true; _currentSortColumn = eventArgs.Column; var direction = (_currentSortColumn.SortDirection != ListSortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending; // Call ISortable Sorting to sort the complete collection if (FullItemsSource != null) { FullItemsSource.Sort(_currentSortColumn.SortMemberPath, direction.ToString()); } _currentSortColumn.SortDirection = null; _currentSortColumn.SortDirection = direction; _currentSortDirection = direction; }
public ColumnInfo(DataGridColumn column) { Header = column.Header; PropertyPath = ((Binding) ((DataGridBoundColumn) column).Binding).Path.Path; WidthValue = column.Width.DisplayValue; WidthType = column.Width.UnitType; SortDirection = column.SortDirection; DisplayIndex = column.DisplayIndex; }