Skip to content

Commit

Permalink
Add SetInitCreateValues function to init values for columns in the Cr…
Browse files Browse the repository at this point in the history
…eate form
  • Loading branch information
gustavnavar committed May 7, 2022
1 parent acb7f14 commit 934b438
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 10 deletions.
5 changes: 5 additions & 0 deletions GridBlazor/CGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@ public Task<bool> InsertColumn(IGridColumn targetColumn, IGridColumn insertingCo
/// </summary>
public QueryDictionary<object> FixedValues { get; set; } = null;

/// <summary>
/// Function to init values for columns in the Create form
/// </summary>
public Func<T, Task> InitCreateValues { get; set; } = null;

/// <summary>
/// Fixed column values for the OData url expand parameter
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions GridBlazor/Client/GridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ public IGridClient<T> ODataCrud(bool createEnabled, Func<T, bool> readEnabled,
return this;
}

public IGridClient<T> SetInitCreateValues(Func<T, Task> initCreateValues)
{
_source.InitCreateValues = initCreateValues;
return this;
}

public IGridClient<T> SetDataAnnotationsValidation(bool enabled = true)
{
_source.DataAnnotationsValidation = enabled;
Expand Down
5 changes: 5 additions & 0 deletions GridBlazor/Client/IGridClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ IGridClient<T> ODataCrud(bool createEnabled, bool readEnabled, bool updateEnable
IGridClient<T> ODataCrud(bool createEnabled, Func<T, bool> readEnabled,
Func<T, bool> updateEnabled, Func<T, bool> deleteEnabled, ICrudFileService<T> crudFileService = null);

/// <summary>
/// Set function to init values for columns in the Create form
/// </summary>
IGridClient<T> SetInitCreateValues(Func<T, Task> initCreateValues);

/// <summary>
/// Enable or disable annotations validation for CRUD views
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>8.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>3.2.7</Version>
<Version>3.2.8</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down
4 changes: 4 additions & 0 deletions GridBlazor/ICGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace GridBlazor
{
public interface ICGrid<T> : ICGrid, IGrid<T>
{
/// <summary>
/// Function to init values for columns in the Create form
/// </summary>
Func<T, Task> InitCreateValues { get; set; }
}

/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions GridBlazor/Pages/GridComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,10 @@ private async Task CreateHndlr()
bool isValid = await OnBeforeCreateForm();
if (isValid)
{
if (((ICGrid<T>)Grid).InitCreateValues != null)
{
await ((ICGrid<T>)Grid).InitCreateValues(Item);
}
if (Grid.FixedValues != null)
{
foreach (var fixValue in Grid.FixedValues)
Expand Down
2 changes: 1 addition & 1 deletion GridBlazor/Pages/GridCreateComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected async Task ButtonFileClicked(string fieldName)
}
}

protected async Task BackButtonClicked()
public async Task BackButtonClicked()
{
await GridComponent.Back();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.2.3</Version>
<Version>3.2.8</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
9 changes: 8 additions & 1 deletion GridBlazorClientSide.Client/Pages/NestedCrudCreateGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ else
.SetStriped(true)
.Crud(true, orderService)
.WithMultipleFilters()
.WithGridItemsCount();
.WithGridItemsCount()
.SetInitCreateValues(InitCreateOrder);

_grid = client.Grid;

Expand Down Expand Up @@ -111,4 +112,10 @@ else
}
return await Task.FromResult(true);
}

private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
}
2 changes: 1 addition & 1 deletion GridBlazorOData.Client/GridBlazorOData.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.2.3</Version>
<Version>3.2.8</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
9 changes: 8 additions & 1 deletion GridBlazorOData.Client/Pages/NestedCrudCreateGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ else
.SetStriped(true)
.ODataCrud(true)
.WithMultipleFilters()
.WithGridItemsCount();
.WithGridItemsCount()
.SetInitCreateValues(InitCreateOrder);

_grid = client.Grid;

Expand Down Expand Up @@ -211,4 +212,10 @@ else
}
return await Task.FromResult(true);
}

private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
}
2 changes: 1 addition & 1 deletion GridBlazorServerSide/GridBlazorServerSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.2.3</Version>
<Version>3.2.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion GridBlazorServerSide/Pages/NestedCrudCreateGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ else
.SetStriped(true)
.Crud(true, orderService)
.WithMultipleFilters()
.WithGridItemsCount();
.WithGridItemsCount()
.SetInitCreateValues(InitCreateOrder);

_grid = client.Grid;

Expand Down Expand Up @@ -111,4 +112,10 @@ else
}
return await Task.FromResult(true);
}

private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
}
2 changes: 1 addition & 1 deletion GridBlazorStandalone/GridBlazorStandalone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.2.3</Version>
<Version>3.2.8</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
9 changes: 8 additions & 1 deletion GridBlazorStandalone/Pages/NestedCrudCreateGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ else
.SetStriped(true)
.Crud(true, orderService)
.WithMultipleFilters()
.WithGridItemsCount();
.WithGridItemsCount()
.SetInitCreateValues(InitCreateOrder);

_grid = client.Grid;

Expand Down Expand Up @@ -114,4 +115,10 @@ else
}
return await Task.FromResult(true);
}

private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
}
21 changes: 21 additions & 0 deletions docs/blazor_client/Crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,25 @@ And finaly you have to pass the paramenters initialized before to the ```GridCom
<GridComponent T="Order" Grid="@_grid" Mode="_mode" Keys="_keys"></GridComponent>
```

## Init values for Create form

You can configure initial values for new records when using the Create form.

You have to use the ```SetInitCreateValues``` of the ```GridClient``` object:

```c#
var client = new GridClient<Order>(HttpClient, url, query, false, "ordersGrid", ColumnCollections.OrderColumnsWithCustomCrud, locale)
.Crud(true, orderService)
.SetDeleteConfirmation(true);
```

And the write the funtion to init the values:
```c#
private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
```

[<- Front-end back-end API](API.md) | [Nested CRUD ->](Nested_crud.md)
21 changes: 21 additions & 0 deletions docs/blazor_local/Crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,25 @@ And finaly you have to pass the paramenters initialized before to the ```GridCom
<GridComponent T="Order" Grid="@_grid" Mode="_mode" Keys="_keys"></GridComponent>
```

## Init values for Create form

You can configure initial values for new records when using the Create form.

You have to use the ```SetInitCreateValues``` of the ```GridClient``` object:

```c#
var client = new GridClient<Order>(q => orderService.GetOrdersGridRows(columns, q), query, false, "ordersGrid", columns, locale)
.Crud(true, orderService)
.SetDeleteConfirmation(true);
```

And the write the funtion to init the values:
```c#
private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
```

[<- Passing grid state as parameter](Passing_grid_state_as_parameter.md) | [Nested CRUD ->](Nested_crud.md)
21 changes: 21 additions & 0 deletions docs/blazor_odata/Crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,25 @@ And finaly you have to pass the paramenters initialized before to the ```GridCom
<GridComponent T="Order" Grid="@_grid" Mode="_mode" Keys="_keys"></GridComponent>
```

## Init values for Create form

You can configure initial values for new records when using the Create form.

You have to use the ```SetInitCreateValues``` of the ```GridODataClient``` object:

```c#
var client = new GridODataClient<Order>(HttpClient, url, query, false, "ordersGrid", columns, 10, locale)
.Crud(true, orderService)
.SetDeleteConfirmation(true);
```

And the write the funtion to init the values:
```c#
private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
```

[<- Front-end back-end API](API.md) | [Nested CRUD ->](Nested_crud.md)
21 changes: 21 additions & 0 deletions docs/blazor_server/Crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,25 @@ And finaly you have to pass the paramenters initialized before to the ```GridCom
<GridComponent T="Order" Grid="@_grid" Mode="_mode" Keys="_keys"></GridComponent>
```

## Init values for Create form

You can configure initial values for new records when using the Create form.

You have to use the ```SetInitCreateValues``` of the ```GridClient``` object:

```c#
var client = new GridClient<Order>(q => orderService.GetOrdersGridRows(columns, q), query, false, "ordersGrid", columns, locale)
.Crud(true, orderService)
.SetDeleteConfirmation(true);
```

And the write the funtion to init the values:
```c#
private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
```

[<- Passing grid state as parameter](Passing_grid_state_as_parameter.md) | [Nested CRUD ->](Nested_crud.md)
21 changes: 21 additions & 0 deletions docs/dotnetcore_blazor/Crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,25 @@ And finaly you have to pass the paramenters initialized before to the ```GridCom
<GridComponent T="Order" Grid="@_grid" Mode="_mode" Keys="_keys"></GridComponent>
```

## Init values for Create form

You can configure initial values for new records when using the Create form.

You have to use the ```SetInitCreateValues``` of the ```GridClient``` object:

```c#
var client = new GridClient<Order>(q => orderService.GetOrdersGridRows(columns, q), query, false, "ordersGrid", columns, locale)
.Crud(true, orderService)
.SetDeleteConfirmation(true);
```

And the write the funtion to init the values:
```c#
private async Task InitCreateOrder(Order order)
{
order.Freight = 50;
await Task.CompletedTask;
}
```

[<- Passing grid state as parameter](Passing_grid_state_as_parameter.md) | [Nested CRUD ->](Nested_crud.md)

0 comments on commit 934b438

Please sign in to comment.