This example sorts list view data by a class property and prevents users from modifying the sorting settings.
-
Create a view controller in the application model and configure sorting settings for the list view's column:
File to review: SortListViewController.cs
protected override void OnActivated() { base.OnActivated(); string propertyName = nameof(Issue.ModifiedOn); bool demoFlag = true; // This code applies a client side sorting. if(demoFlag) { IModelColumn columnInfo = View.Model.Columns[propertyName]; if(columnInfo != null) { columnInfo.SortIndex = 0; columnInfo.SortOrder = ColumnSortOrder.Descending; } } else { // This code is used for the server side sorting. if(View.Model.Sorting[propertyName] == null) { IModelSortProperty sortProperty = View.Model.Sorting.AddNode<IModelSortProperty>(propertyName); sortProperty.Direction = SortingDirection.Descending; sortProperty.PropertyName = propertyName; } } }
-
Implement platform-dependent controllers that disable the sorting functionality in underlying grid controls:
File to review: BlazorSortListViewController.cs
protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); if(View.Editor is DxGridListEditor gridListEditor) { foreach(DxGridDataColumnModel columnModel in gridListEditor.GridDataColumnModels) { columnModel.AllowSort = false; } } }
File to review: WinSortListViewController.cs
protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); if(View.Editor is GridListEditor gridListEditor) { gridListEditor.GridView.OptionsCustomization.AllowSort = false; } }
This approach allows you to sort both nested and root list views, and works if server mode is enabled in the list view.
- Application Model (UI Settings Storage)
- Read and Set Values for Built-in Application Model Nodes in Code
- How to: Access the Grid Component in a List View
(you will be redirected to DevExpress.com to submit your response)