-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AfterChangeValue grid column event
- Loading branch information
1 parent
f5cce95
commit a97142e
Showing
25 changed files
with
771 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@page "/afterchangevalue" | ||
@using GridBlazorClientSide.Client.ColumnCollections | ||
@using GridBlazorClientSide.Shared.Models | ||
@using Microsoft.Extensions.Primitives | ||
@using System.Globalization | ||
@using System.Threading.Tasks | ||
@inject NavigationManager NavigationManager | ||
@inject HttpClient HttpClient | ||
@inject ICrudDataService<Order> orderService | ||
|
||
<h1>Grid Sample</h1> | ||
|
||
<p> | ||
This page contains a CRUD grid implementing an event to modify the OrderDate after the CustomerID is changed on the Create form | ||
</p> | ||
|
||
<p> | ||
This component demonstrates a GridBlazor client-side grid. For more information, please see: <a href="https://github.com/gustavnavar/Grid.Blazor">https://github.com/gustavnavar/Grid.Blazor</a> | ||
</p> | ||
|
||
@if (_task.IsCompleted) | ||
{ | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<GridComponent T="Order" Grid="@_grid"></GridComponent> | ||
</div> | ||
</div> | ||
} | ||
else | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
|
||
@code | ||
{ | ||
private CGrid<Order> _grid; | ||
private Task _task; | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
var locale = CultureInfo.CurrentCulture; | ||
|
||
var query = new QueryDictionary<StringValues>(); | ||
string url = NavigationManager.BaseUri + "api/SampleData/OrderColumnsWithCrud"; | ||
|
||
Func<Order, GridMode, Task> afterChangeCustomerID = async (order, mode) => | ||
{ | ||
if (mode == GridMode.Create) | ||
{ | ||
order.OrderDate = DateTime.Now; | ||
StateHasChanged(); | ||
await Task.CompletedTask; | ||
} | ||
}; | ||
|
||
var client = new GridClient<Order>(HttpClient, url, query, false, "ordersGrid", c => | ||
ColumnCollections.OrderColumnsWithCrudAfterChange(c, afterChangeCustomerID, NavigationManager.BaseUri), locale) | ||
.Sortable() | ||
.Filterable() | ||
.SetStriped(true) | ||
.Crud(true, orderService) | ||
.WithMultipleFilters() | ||
.WithGridItemsCount(); | ||
|
||
_grid = client.Grid; | ||
|
||
// Set new items to grid | ||
_task = client.UpdateGrid(); | ||
await _task; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
@page "/afterchangevalue" | ||
@using GridBlazor.Resources | ||
@using GridShared.Columns | ||
@using GridBlazorOData.Client.Resources | ||
@using GridBlazorOData.Shared.Models | ||
@using Microsoft.Extensions.Primitives | ||
@using System.Globalization | ||
@using System.Threading.Tasks | ||
@inject NavigationManager NavigationManager | ||
@inject HttpClient HttpClient | ||
|
||
<h1>Grid Sample</h1> | ||
|
||
<p> | ||
This page contains a CRUD grid implementing an event to modify the OrderDate after the CustomerID is changed on the Create form | ||
</p> | ||
|
||
<p> | ||
This component demonstrates a GridBlazor client-side grid with an OData back-end. For more information, please see: <a href="https://github.com/gustavnavar/Grid.Blazor">https://github.com/gustavnavar/Grid.Blazor</a> | ||
</p> | ||
|
||
@if (_task.IsCompleted) | ||
{ | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<GridComponent T="Order" Grid="@_grid"></GridComponent> | ||
</div> | ||
</div> | ||
} | ||
else | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
|
||
@code | ||
{ | ||
private CGrid<Order> _grid; | ||
private Task _task; | ||
|
||
protected override async Task OnParametersSetAsync() | ||
{ | ||
var locale = CultureInfo.CurrentCulture; | ||
|
||
var query = new QueryDictionary<StringValues>(); | ||
|
||
Action<IGridColumnCollection<Order>, Func<Order, GridMode, Task>, string> columns = (c, afterChangeCustomerID, baseUri) => | ||
{ | ||
c.Add(o => o.OrderID).SetPrimaryKey(true).Titled(SharedResource.Number).SetWidth(100); | ||
c.Add(o => o.CustomerID, true).SetSelectField(true, o => o.Customer.CustomerID + " - " + o.Customer.CompanyName, o => GetAllCustomers(baseUri)).SetAfterChangeValue(afterChangeCustomerID); | ||
c.Add(o => o.EmployeeID, true).SetSelectField(true, o => o.Employee.EmployeeID.ToString() + " - " + o.Employee.FirstName + " " + o.Employee.LastName, o => GetAllEmployees(baseUri)); | ||
c.Add(o => o.ShipVia, true).SetSelectField(true, o => o.Shipper == null ? "" : o.Shipper.ShipperID.ToString() + " - " + o.Shipper.CompanyName, () => GetAllShippers(baseUri)); | ||
c.Add(o => o.OrderDate, "OrderCustomDate").Titled(SharedResource.OrderCustomDate).Format("{0:yyyy-MM-dd}").SetWidth(120).SetCrudWidth(3); | ||
c.Add(o => o.Customer.CompanyName).Titled(SharedResource.CompanyName).SetWidth(250).SetCrudHidden(true).SetReadOnlyOnUpdate(true); | ||
c.Add(o => o.Customer.ContactName).Titled(SharedResource.ContactName).SetCrudHidden(true); | ||
c.Add(o => o.Freight).Titled(SharedResource.Freight).SetWidth(150).Format("{0:#,##0.00}"); | ||
c.Add(o => o.Customer.IsVip).Titled(SharedResource.IsVip).SetWidth(90).Css("hidden-xs").RenderValueAs(o => o.Customer.IsVip ? Strings.BoolTrueLabel : Strings.BoolFalseLabel).SetCrudHidden(true); | ||
c.Add(o => o.RequiredDate, true).Format("{0:yyyy-MM-dd}").SetCrudWidth(3); | ||
c.Add(o => o.ShippedDate, true).Format("{0:yyyy-MM-dd}").SetCrudWidth(3); | ||
c.Add(o => o.ShipName, true); | ||
c.Add(o => o.ShipAddress, true); | ||
c.Add(o => o.ShipCity, true); | ||
c.Add(o => o.ShipPostalCode, true); | ||
c.Add(o => o.ShipRegion, true); | ||
c.Add(o => o.ShipCountry, true); | ||
c.Add(true).Titled("Images").RenderCrudComponentAs<Carousel, Carousel, NullComponent, NullComponent>(); | ||
}; | ||
|
||
Func<Order, GridMode, Task> afterChangeCustomerID = async (order, mode) => | ||
{ | ||
if (mode == GridMode.Create) | ||
{ | ||
order.OrderDate = DateTime.Now; | ||
StateHasChanged(); | ||
await Task.CompletedTask; | ||
} | ||
}; | ||
|
||
string url = NavigationManager.BaseUri + "odata/Orders"; | ||
var client = new GridODataClient<Order>(HttpClient, url, query, false, "ordersGrid", | ||
c => columns(c, afterChangeCustomerID, NavigationManager.BaseUri), 10, locale, new List<string> { "Employee", "Shipper" }) | ||
.Sortable() | ||
.Filterable() | ||
.SetStriped(true) | ||
.ODataCrud(true) | ||
.WithMultipleFilters() | ||
.WithGridItemsCount(); | ||
|
||
_grid = client.Grid; | ||
|
||
// Set new items to grid | ||
_task = client.UpdateGrid(); | ||
await _task; | ||
} | ||
|
||
Func<string, Task<IEnumerable<SelectItem>>> GetAllCustomers = async (baseUri) => | ||
{ | ||
string url = baseUri + $"odata/Customers?$select=CustomerID,CompanyName"; | ||
ODataDTO<Customer> response = await new HttpClient().GetFromJsonAsync<ODataDTO<Customer>>(url); | ||
if (response == null || response.Value == null) | ||
{ | ||
return new List<SelectItem>(); | ||
} | ||
else | ||
{ | ||
return response.Value | ||
.Select(r => new SelectItem(r.CustomerID, r.CustomerID + " - " + r.CompanyName)) | ||
.ToList(); | ||
} | ||
}; | ||
|
||
Func<string, Task<IEnumerable<SelectItem>>> GetAllEmployees = async (baseUri) => | ||
{ | ||
string url = baseUri + $"odata/Employees?$select=EmployeeID,FirstName,LastName"; | ||
ODataDTO<Employee> response = await new HttpClient().GetFromJsonAsync<ODataDTO<Employee>>(url); | ||
if (response == null || response.Value == null) | ||
{ | ||
return new List<SelectItem>(); | ||
} | ||
else | ||
{ | ||
return response.Value | ||
.Select(r => new SelectItem(r.EmployeeID.ToString(), r.EmployeeID.ToString() + " - " + r.FirstName + " " + r.LastName)) | ||
.ToList(); | ||
} | ||
}; | ||
|
||
Func<string, Task<IEnumerable<SelectItem>>> GetAllShippers = async (baseUri) => | ||
{ | ||
string url = baseUri + $"odata/Shippers?$select=ShipperID,CompanyName"; | ||
ODataDTO<Shipper> response = await new HttpClient().GetFromJsonAsync<ODataDTO<Shipper>>(url); | ||
if (response == null || response.Value == null) | ||
{ | ||
return new List<SelectItem>(); | ||
} | ||
else | ||
{ | ||
return response.Value | ||
.Select(r => new SelectItem(r.ShipperID.ToString(), r.ShipperID.ToString() + " - " + r.CompanyName)) | ||
.ToList(); | ||
} | ||
}; | ||
} |
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
Oops, something went wrong.