Skip to content

Commit

Permalink
Add example of new rank sort extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbu committed Apr 16, 2024
1 parent 2e6b709 commit 56e0495
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/Demo/Shared/Pages/DataGrid/DataGridPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
</Description>
</DemoSection>

<DemoSection Title="SortBy Rank" Component="@typeof(DataGridRankSort)">
<Description>
<p>
Here is an example that demonstrates the rank sort.
</p>
</Description>
</DemoSection>


<DemoSection Title="Remote data" Component="@typeof(DataGridRemoteData)">
<Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<FluentDataGrid Items="@_gridData" ResizableColumns=true GridTemplateColumns="0.5fr 0.5fr">
<PropertyColumn Sortable="true" Property="x => x.Number" Title="Number" />

<TemplateColumn Sortable="true" SortBy="groupRank" Title="Group">
@context.Group
</TemplateColumn>

</FluentDataGrid>

<p>Keep numbers always sorted ascending inside the group when sorting by group</p>
<FluentDataGrid Items="@_gridData" ResizableColumns=true GridTemplateColumns="0.5fr 0.5fr">
<PropertyColumn Sortable="true" Property="x => x.Number" Title="Number" />

<TemplateColumn Sortable="true" SortBy="groupRankNumberAlwaysAscending" Title="Group">
@context.Group
</TemplateColumn>

</FluentDataGrid>



@code {
GridSort<GridRow> groupRank = GridSort<GridRow>
.ByAscending(x => x.Group)
.ThenAscending(x => x.Number);

GridSort<GridRow> groupRankNumberAlwaysAscending = GridSort<GridRow>
.ByAscending(x => x.Group)
.ThenAlwaysAscending(x => x.Number);

private static readonly IQueryable<GridRow> _gridData = new GridRow[] {
new(2, "B"),
new(1, "A"),
new(4, "B"),
new(3, "A")
}.AsQueryable();

public class GridRow(int number, string group)
{
public int Number { get; } = number;
public string Group { get; } = group;
}
}

0 comments on commit 56e0495

Please sign in to comment.