Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
using System;
using DevExpress.Data;
using DevExpress.Xpo.DB;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Model;
using SortListView.Module.BusinessObjects;
using DevExpress.ExpressApp.Editors;

namespace SortListViewEF.Module {
public abstract class SortListViewControllerBase : ObjectViewController<ListView, Issue> {
protected override void OnActivated() {
public class SortListViewController : ObjectViewController<ListView, Issue> {

string propertyName = nameof(Issue.ModifiedOn);
bool demoFlag = true;

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;
if (!demoFlag && View.Model.Sorting[propertyName] == null)
{
// This code applies a server side sorting.
IModelSortProperty sortProperty = View.Model.Sorting.AddNode<IModelSortProperty>(propertyName);
sortProperty.Direction = SortingDirection.Ascending;
sortProperty.PropertyName = propertyName;
}
}

protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
if (View.Editor is ColumnsListEditor listEditor)
{
foreach (var columnWrapper in listEditor.Columns)
{
columnWrapper.AllowSortingChange = false;
// This code applies a client side sorting.
if (demoFlag && columnWrapper.PropertyName == propertyName)
{
columnWrapper.SortIndex = 0;
columnWrapper.SortOrder = ColumnSortOrder.Descending;
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion CS/EFCore/SortListViewEF/SortListViewEF.Module/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public SortListViewEFModule() {
// SortListViewEFModule
//
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule));
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule));
}
public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {
ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
using DevExpress.Data;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Model;
using DevExpress.Xpo.DB;
using SortListView.Module.BusinessObjects;

namespace SortListView.Module {
public abstract class SortListViewControllerBase : ObjectViewController<ListView, Issue> {
protected override void OnActivated() {
public class SortListViewController : ObjectViewController<ListView, Issue> {

string propertyName = nameof(Issue.ModifiedOn);
bool demoFlag = true;

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;
if (!demoFlag && View.Model.Sorting[propertyName] == null)
{
// This code applies a server side sorting.
IModelSortProperty sortProperty = View.Model.Sorting.AddNode<IModelSortProperty>(propertyName);
sortProperty.Direction = SortingDirection.Ascending;
sortProperty.PropertyName = propertyName;
}
}

protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
if (View.Editor is ColumnsListEditor listEditor)
{
foreach (var columnWrapper in listEditor.Columns)
{
columnWrapper.AllowSortingChange = false;
// This code applies a client side sorting.
if (demoFlag && columnWrapper.PropertyName == propertyName)
{
columnWrapper.SortIndex = 0;
columnWrapper.SortOrder = ColumnSortOrder.Descending;
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion CS/XPO/SortListView/SortListView.Module/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public SortListViewModule() {
// SortListViewModule
//
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule));
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule));
}
public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {
ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
Expand Down

This file was deleted.

79 changes: 50 additions & 29 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- default badges list -->
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128593846/25.2.1%2B)
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E1276)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
Expand All @@ -13,59 +12,83 @@ This example sorts list view data by a class property and prevents users from mo

## Implementation Details

1. Create a view controller in the application model and configure sorting settings for the list view's column:
1. Create a view controller in the application model and configure sorting settings for the list view's columns and editor controls:

_File to review:_ [SortListViewController.cs](CS/EFCore/SortListViewEF/SortListViewEF.Module/Controllers/SortListViewController.cs)
```cs
protected override void OnActivated() {
base.OnActivated();
public class SortListViewController : ObjectViewController<ListView, Issue> {

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) {

protected override void OnActivated()
{
base.OnActivated();
if (!demoFlag && View.Model.Sorting[propertyName] == null)
{
// This code applies a server side sorting.
IModelSortProperty sortProperty = View.Model.Sorting.AddNode<IModelSortProperty>(propertyName);
sortProperty.Direction = SortingDirection.Descending;
sortProperty.Direction = SortingDirection.Ascending;
sortProperty.PropertyName = propertyName;
}
}

protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
if (View.Editor is ColumnsListEditor listEditor)
{
foreach (var columnWrapper in listEditor.Columns)
{
columnWrapper.AllowSortingChange = false;
// This code applies a client side sorting.
if (demoFlag && columnWrapper.PropertyName == propertyName)
{
columnWrapper.SortIndex = 0;
columnWrapper.SortOrder = ColumnSortOrder.Descending;
}
}
}
}
}
```

2. Implement platform-dependent controllers that disable the sorting functionality in underlying grid controls:
This approach allows you to sort both nested and root list views, and works if server mode is enabled in the list view.

## Approach using platform-dependent API:
### Blazor:

_File to review:_ [BlazorSortListViewController.cs](CS/EFCore/SortListViewEF/SortListViewEF.Blazor.Server/Controllers/BlazorSortListViewController.cs)
```cs
protected override void OnViewControlsCreated() {
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
if(View.Editor is DxGridListEditor gridListEditor) {
foreach(DxGridDataColumnModel columnModel in gridListEditor.GridDataColumnModels) {
columnModel.AllowSort = false;
if(View.Editor is DxGridListEditor gridListEditor)
{
foreach (DxGridColumnWrapper column in gridListEditor.Columns)
{
column.AllowSortingChange = false;
}
}
}
```

_File to review:_ [WinSortListViewController.cs](CS/EFCore/SortListViewEF/SortListViewEF.Win/Controllers/WinSortListViewController.cs)
### Win:

```cs
protected override void OnViewControlsCreated() {
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
if(View.Editor is GridListEditor gridListEditor) {
gridListEditor.GridView.OptionsCustomization.AllowSort = false;
if(View.Editor is GridListEditor gridListEditor && gridListEditor.GridView != null)
{
foreach(WinGridColumnWrapper columnWrapper in gridListEditor.Columns)
{
columnWrapper.Column.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
columnWrapper.Column.OptionsColumn.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
}
}
}
```

This approach allows you to sort both nested and root list views, and works if server mode is enabled in the list view.

## Documentation

- [Application Model (UI Settings Storage)](https://docs.devexpress.com/eXpressAppFramework/112579/ui-construction/application-model-ui-settings-storage)
Expand All @@ -75,8 +98,6 @@ This approach allows you to sort both nested and root list views, and works if s
## Files to Review

- [SortListViewController.cs](CS/EFCore/SortListViewEF/SortListViewEF.Module/Controllers/SortListViewController.cs)
- [BlazorSortListViewController.cs](CS/EFCore/SortListViewEF/SortListViewEF.Blazor.Server/Controllers/BlazorSortListViewController.cs)
- [WinSortListViewController.cs](CS/EFCore/SortListViewEF/SortListViewEF.Win/Controllers/WinSortListViewController.cs)



Expand Down
Loading