-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MultiCriteriaSortingOptions implemented
- Loading branch information
1 parent
e948cff
commit c8ce132
Showing
10 changed files
with
141 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Framework/Core/Controls/Options/GridViewDataSetOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace DotVVM.Framework.Controls | ||
{ | ||
public class GridViewDataSetOptions<TFilteringOptions, TSortingOptions, TPagingOptions> | ||
where TFilteringOptions : IFilteringOptions | ||
where TSortingOptions : ISortingOptions | ||
where TPagingOptions : IPagingOptions | ||
{ | ||
public TFilteringOptions? FilteringOptions { get; set; } = default; | ||
|
||
public TSortingOptions? SortingOptions { get; set; } = default; | ||
|
||
public TPagingOptions? PagingOptions { get; set; } = default; | ||
} | ||
|
||
public class GridViewDataSetOptions : GridViewDataSetOptions<NoFilteringOptions, SortingOptions, PagingOptions> | ||
{ | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Framework/Core/Controls/Options/IPagingOptionsLoadingPostProcessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace DotVVM.Framework.Controls; | ||
|
||
public interface IPagingOptionsLoadingPostProcessor | ||
{ | ||
void ProcessLoadedItems<T>(IQueryable<T> filteredQueryable, IList<T> items); | ||
} |
77 changes: 77 additions & 0 deletions
77
src/Framework/Core/Controls/Options/MultiCriteriaSortingOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace DotVVM.Framework.Controls; | ||
|
||
public class MultiCriteriaSortingOptions : SortingOptions, ISortingMultipleCriteriaCapability | ||
{ | ||
public IList<SortCriterion> Criteria { get; set; } = new List<SortCriterion>(); | ||
|
||
public int MaxSortCriteriaCount { get; set; } = 3; | ||
|
||
public override IQueryable<T> ApplyToQueryable<T>(IQueryable<T> queryable) | ||
{ | ||
foreach (var criterion in Criteria.Reverse()) | ||
{ | ||
queryable = SortingImplementation.ApplySortingToQueryable(queryable, criterion.SortExpression, criterion.SortDescending); | ||
} | ||
|
||
return base.ApplyToQueryable(queryable); | ||
} | ||
|
||
public override void SetSortExpression(string? sortExpression) | ||
{ | ||
if (SortExpression == null) | ||
{ | ||
SortExpression = sortExpression; | ||
SortDescending = false; | ||
} | ||
else if (sortExpression == SortExpression) | ||
{ | ||
if (!SortDescending) | ||
{ | ||
SortDescending = true; | ||
} | ||
else if (Criteria.Any()) | ||
{ | ||
SortExpression = Criteria[0].SortExpression; | ||
SortDescending = Criteria[0].SortDescending; | ||
Criteria.RemoveAt(0); | ||
} | ||
else | ||
{ | ||
SortExpression = null; | ||
SortDescending = false; | ||
} | ||
} | ||
else | ||
{ | ||
var index = Criteria.ToList().FindIndex(c => c.SortExpression == sortExpression); | ||
if (index >= 0) | ||
{ | ||
if (!Criteria[index].SortDescending) | ||
{ | ||
Criteria[index].SortDescending = true; | ||
} | ||
else | ||
{ | ||
Criteria.RemoveAt(index); | ||
} | ||
} | ||
else | ||
{ | ||
if (Criteria.Count < MaxSortCriteriaCount - 1) | ||
{ | ||
Criteria.Add(new SortCriterion() { SortExpression = sortExpression }); | ||
} | ||
else | ||
{ | ||
SortExpression = sortExpression; | ||
SortDescending = false; | ||
Criteria.Clear(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
src/Framework/Framework/Controls/GridViewDataSetOptions.cs
This file was deleted.
Oops, something went wrong.