Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #870 from riganti/Grid-SortChanged-precedence
GridView.SortChange has precedence over default sorting
- Loading branch information
Showing
6 changed files
with
206 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
66 changes: 66 additions & 0 deletions
66
src/DotVVM.Samples.Common/ViewModels/ControlSamples/GridView/GridViewSortChangedViewModel.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,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotVVM.Framework.Controls; | ||
using DotVVM.Framework.ViewModel; | ||
using DotVVM.Samples.BasicSamples.ViewModels.ControlSamples.GridView; | ||
|
||
namespace DotVVM.Samples.Common.ViewModels.ControlSamples.GridView | ||
{ | ||
public class GridViewSortChangedViewModel : DotvvmViewModelBase | ||
{ | ||
|
||
private static IQueryable<CustomerData> GetData() | ||
{ | ||
return new[] | ||
{ | ||
new CustomerData() { CustomerId = 1, Name = "John Doe", BirthDate = DateTime.Parse("1976-04-01"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 2, Name = "John Deer", BirthDate = DateTime.Parse("1984-03-02"), MessageReceived = false }, | ||
new CustomerData() { CustomerId = 3, Name = "Johnny Walker", BirthDate = DateTime.Parse("1934-01-03"), MessageReceived = true}, | ||
new CustomerData() { CustomerId = 4, Name = "Jim Hacker", BirthDate = DateTime.Parse("1912-11-04"), MessageReceived = true}, | ||
new CustomerData() { CustomerId = 5, Name = "Joe E. Brown", BirthDate = DateTime.Parse("1947-09-05"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 6, Name = "Jim Harris", BirthDate = DateTime.Parse("1956-07-06"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 7, Name = "J. P. Morgan", BirthDate = DateTime.Parse("1969-05-07"), MessageReceived = false }, | ||
new CustomerData() { CustomerId = 8, Name = "J. R. Ewing", BirthDate = DateTime.Parse("1987-03-08"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 9, Name = "Jeremy Clarkson", BirthDate = DateTime.Parse("1994-04-09"), MessageReceived = false }, | ||
new CustomerData() { CustomerId = 10, Name = "Jenny Green", BirthDate = DateTime.Parse("1947-02-10"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 11, Name = "Joseph Blue", BirthDate = DateTime.Parse("1948-12-11"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 12, Name = "Jack Daniels", BirthDate = DateTime.Parse("1968-10-12"), MessageReceived = true}, | ||
new CustomerData() { CustomerId = 13, Name = "Jackie Chan", BirthDate = DateTime.Parse("1978-08-13"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 14, Name = "Jasper", BirthDate = DateTime.Parse("1934-06-14"), MessageReceived = false}, | ||
new CustomerData() { CustomerId = 15, Name = "Jumbo", BirthDate = DateTime.Parse("1965-06-15"), MessageReceived = false }, | ||
new CustomerData() { CustomerId = 16, Name = "Junkie Doodle", BirthDate = DateTime.Parse("1977-05-16"), MessageReceived = false } | ||
}.AsQueryable(); | ||
} | ||
|
||
public GridViewDataSet<CustomerData> CustomersDataSet { get; set; } = new GridViewDataSet<CustomerData>() | ||
{ | ||
PagingOptions = new PagingOptions() | ||
{ | ||
PageSize = 10 | ||
}, | ||
SortingOptions = new SortingOptions() | ||
{ | ||
SortExpression = nameof(CustomerData.CustomerId) | ||
} | ||
}; | ||
|
||
public override Task PreRender() | ||
{ | ||
if (CustomersDataSet.IsRefreshRequired) | ||
{ | ||
CustomersDataSet.LoadFromQueryable(GetData()); | ||
} | ||
|
||
return base.PreRender(); | ||
} | ||
|
||
public void CustomSort(string column) | ||
{ | ||
CustomersDataSet.SortingOptions.SortExpression = column; | ||
CustomersDataSet.SortingOptions.SortDescending = false; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/DotVVM.Samples.Common/Views/ControlSamples/GridView/GridViewSortChanged.dothtml
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,43 @@ | ||
@viewModel DotVVM.Samples.Common.ViewModels.ControlSamples.GridView.GridViewSortChangedViewModel, DotVVM.Samples.Common | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<title>Hello from DotVVM!</title> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>GridView with default sorting logic</h1> | ||
<ul> | ||
<li>Clicking on the column header sorts the data using the particular column in the ascending order.</li> | ||
<li>Subsequent clicks on the column header alternates the changes the order from ascending to descending and vice versa.</li> | ||
</ul> | ||
<dot:GridView DataSource="{value: CustomersDataSet}" class="table table-bordered"> | ||
<Columns> | ||
<dot:GridViewTextColumn HeaderText="Id" ValueBinding="{value: CustomerId}" AllowSorting="True" /> | ||
<dot:GridViewTextColumn HeaderText="Name" ValueBinding="{value: Name}" AllowSorting="True" /> | ||
<dot:GridViewTextColumn HeaderText="Birth Date" ValueBinding="{value: BirthDate}" FormatString="g" AllowSorting="True" /> | ||
<dot:GridViewCheckBoxColumn HeaderText="Message received" ValueBinding="{value: MessageReceived}" AllowSorting="True" /> | ||
</Columns> | ||
</dot:GridView> | ||
|
||
<h1>GridView with custom sorting logic</h1> | ||
<ul> | ||
<li>Clicking on the column header sorts the data using the particular column in the ascending order.</li> | ||
<li>Subsequent clicks on the column header do nothing special - the order is always ascending.</li> | ||
</ul> | ||
<dot:GridView DataSource="{value: CustomersDataSet}" SortChanged="{command: CustomSort}" class="table table-bordered"> | ||
<Columns> | ||
<dot:GridViewTextColumn HeaderText="Id" ValueBinding="{value: CustomerId}" AllowSorting="True" /> | ||
<dot:GridViewTextColumn HeaderText="Name" ValueBinding="{value: Name}" AllowSorting="True" /> | ||
<dot:GridViewTextColumn HeaderText="Birth Date" ValueBinding="{value: BirthDate}" FormatString="g" AllowSorting="True" /> | ||
<dot:GridViewCheckBoxColumn HeaderText="Message received" ValueBinding="{value: MessageReceived}" AllowSorting="True" /> | ||
</Columns> | ||
</dot:GridView> | ||
|
||
<p> | ||
Sort Expression: <span class="result-sortexpression">{{value: CustomersDataSet.SortingOptions.SortExpression}}</span><br /> | ||
Sort Descending: <span class="result-sortdescending">{{value: CustomersDataSet.SortingOptions.SortDescending}}</span> | ||
</p> | ||
</div> | ||
</body> | ||
</html> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.