The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
In my grouped grid i want to keep the data to be always sorted by one of the columns, say, "IsNew" column. Then I'd like allow user to sort by other columns as they wish (the "IsNew" column is hidden). However I found whenever user clicks on the column header to change sorting, the SortedColumns collection is cleared. To fix this, I tried to handle TableDescriptor.SortedColumns.Changed event and add the column back:
void SortedColumns_Changed(object sender, ListPropertyChangedEventArgs e) { if (!this.grid.TableDescriptor.SortedColumns.Contains("IsNew")) this.grid.TableDescriptor.SortedColumns.Insert(0, new SortColumnDescriptor("IsNew", ListSortDirection.Ascending)); }
After this change I found when i click on any colum header to sort the data, the colum keeps in ascending order. I trace down the event and found out that no matter how many times i click the column header the ListSortDirection is alwasy Ascending, instead of flipping between ascending/descending as before. Any ideas?
HAhaneefm Syncfusion Team July 10, 2007 07:57 PM UTC
Hi Stanley,
This can be achieved by handling a the TableControlQueryAllowSortColumn event handler and set the e.AllowSort property to false to cancel default grid sorting for the required columns. Please try the following code snippet and let me know if this helps
void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, GridQueryAllowSortColumnEventArgs e) { e.AllowSort = false; ListSortDirection direction = ListSortDirection.Ascending; if (this.gridGroupingControl1.TableDescriptor.SortedColumns.Contains(e.Column.Name)) { direction = this.gridGroupingControl1.TableDescriptor.SortedColumns[e.Column.Name].SortDirection; direction = direction == ListSortDirection.Descending ? ListSortDirection.Ascending : ListSortDirection.Descending; } this.gridGroupingControl1.TableDescriptor.SortedColumns.Clear(); this.gridGroupingControl1.TableDescriptor.SortedColumns.Add("IsNew"); if (e.Column.Name != "IsNew") this.gridGroupingControl1.TableDescriptor.SortedColumns.Add(e.Column.Name, direction); }