-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…stom ValueChanged handler
- Loading branch information
Showing
9 changed files
with
332 additions
and
314 deletions.
There are no files selected for viewing
153 changes: 75 additions & 78 deletions
153
Havit.Blazor.Documentation/Pages/Components/HxFilterFormDoc/HxFilterForm_Demo.razor
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 |
---|---|---|
@@ -1,93 +1,90 @@ | ||
<HxFilterForm @ref="filterForm" Model="@model" ModelChanged="HandleModelChanged" TModel="FormModel" OnChipsUpdated="HandleChipsUpdated"> | ||
<DataAnnotationsValidator /> | ||
<ValidationSummary /> | ||
|
||
<h2>Filter</h2> | ||
|
||
<HxInputText Label="Text1" @bind-Value="@context.Text1" /> | ||
<HxInputText Label="Text2" @bind-Value="@context.Text2"> | ||
<ChipTemplate> | ||
Haha! There is also a chip with custom template! (value @context.Text2) | ||
</ChipTemplate> | ||
</HxInputText> | ||
<HxInputNumber Label="Number 1" @bind-Value="@context.Number1" /> | ||
|
||
<HxSubmit Text="Apply" Color="ThemeColor.Primary" /> | ||
|
||
<h2>Values</h2> | ||
|
||
<h3>Values in filter</h3> | ||
<ul> | ||
<li>Text1: @context.Text1</li> | ||
<li>Text2: @context.Text2</li> | ||
<li>Number1: @context.Number1</li> | ||
</ul> | ||
<HxFilterForm @ref="filterForm" | ||
@bind-Model="@model" | ||
@bind-Model:after="HandleModelChanged" | ||
OnChipsUpdated="HandleChipsUpdated"> | ||
<DataAnnotationsValidator /> | ||
<ValidationSummary /> | ||
|
||
<h2>Filter</h2> | ||
|
||
<HxInputText Label="Text1" @bind-Value="@context.Text1" /> | ||
<HxInputText Label="Text2" @bind-Value="@context.Text2"> | ||
<ChipTemplate> | ||
Haha! There is also a chip with custom template! (value @context.Text2) | ||
</ChipTemplate> | ||
</HxInputText> | ||
<HxInputNumber Label="Number 1" @bind-Value="@context.Number1" /> | ||
|
||
<HxSubmit Text="Apply" Color="ThemeColor.Primary" /> | ||
|
||
<h2>Values</h2> | ||
|
||
<h3>Values in filter</h3> | ||
<ul> | ||
<li>Text1: @context.Text1</li> | ||
<li>Text2: @context.Text2</li> | ||
<li>Number1: @context.Number1</li> | ||
</ul> | ||
</HxFilterForm> | ||
|
||
<h3>Values in model</h3> | ||
<ul> | ||
<li>Text1: @model.Text1</li> | ||
<li>Text2: @model.Text2</li> | ||
<li>Text3: @model.Number1</li> | ||
<li>Text1: @model.Text1</li> | ||
<li>Text2: @model.Text2</li> | ||
<li>Text3: @model.Number1</li> | ||
</ul> | ||
|
||
<h4>Chips</h4> | ||
|
||
<HxChipList Chips="@chips" OnChipRemoveClick="HandleChipRemoveClick" /> | ||
|
||
<HxGrid @ref="myGrid" TItem="string" DataProvider="@GridDataProvider"> | ||
<Columns> | ||
<HxGridColumn TItem="string" HeaderText="Value" ItemTextSelector="(item) => item" /> | ||
</Columns> | ||
<Columns> | ||
<HxGridColumn TItem="string" HeaderText="Value" ItemTextSelector="(item) => item" /> | ||
</Columns> | ||
</HxGrid> | ||
|
||
@code { | ||
protected FormModel model = new FormModel { Text1 = "initial value" }; | ||
private HxGrid<string> myGrid; | ||
|
||
private HxFilterForm<FormModel> filterForm; | ||
private ChipItem[] chips; | ||
|
||
private void HandleChipsUpdated(ChipItem[] chips) | ||
{ | ||
this.chips = chips; | ||
} | ||
|
||
private async Task HandleChipRemoveClick(ChipItem chipToRemove) | ||
{ | ||
await filterForm.RemoveChipAsync(chipToRemove); | ||
} | ||
|
||
#region Nested class FormModel | ||
public class FormModel : ICloneable | ||
{ | ||
[Required] | ||
[MaxLength(20)] | ||
public string Text1 { get; set; } | ||
|
||
public string Text2 { get; set; } | ||
|
||
public int Number1 { get; set; } = 5; | ||
|
||
public object Clone() => MemberwiseClone(); | ||
} | ||
#endregion | ||
|
||
private async Task HandleModelChanged(FormModel newModel) | ||
{ | ||
model = newModel; | ||
//StateHasChanged(); | ||
await myGrid.RefreshDataAsync(); | ||
} | ||
|
||
private async Task<GridDataProviderResult<string>> GridDataProvider(GridDataProviderRequest<string> request) | ||
{ | ||
await Task.Delay(3000); // simulate server call | ||
var stringValues = new List<string>(); | ||
stringValues.Add(model.Text1); | ||
stringValues.Add(model.Text2); | ||
stringValues.Add(model.Number1.ToString()); | ||
return request.ApplyTo(stringValues); | ||
} | ||
protected FormModel model = new FormModel { Text1 = "initial value" }; | ||
private HxGrid<string> myGrid; | ||
private HxFilterForm<FormModel> filterForm; | ||
private ChipItem[] chips; | ||
|
||
private void HandleChipsUpdated(ChipItem[] chips) | ||
{ | ||
this.chips = chips; | ||
} | ||
|
||
private async Task HandleChipRemoveClick(ChipItem chipToRemove) | ||
{ | ||
await filterForm.RemoveChipAsync(chipToRemove); | ||
} | ||
|
||
private async Task HandleModelChanged() | ||
{ | ||
await myGrid.RefreshDataAsync(); | ||
} | ||
|
||
private async Task<GridDataProviderResult<string>> GridDataProvider(GridDataProviderRequest<string> request) | ||
{ | ||
await Task.Delay(3000); // simulate server call | ||
var stringValues = new List<string>(); | ||
stringValues.Add(model.Text1); | ||
stringValues.Add(model.Text2); | ||
stringValues.Add(model.Number1.ToString()); | ||
return request.ApplyTo(stringValues); | ||
} | ||
|
||
public class FormModel : ICloneable | ||
{ | ||
[Required, MaxLength(20)] | ||
public string Text1 { get; set; } | ||
|
||
public string Text2 { get; set; } | ||
|
||
public int Number1 { get; set; } = 5; | ||
|
||
public object Clone() => MemberwiseClone(); | ||
} | ||
} |
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
107 changes: 0 additions & 107 deletions
107
Havit.Blazor.Documentation/Pages/Components/HxListLayoutDoc/HxListLayout_Demo.razor
This file was deleted.
Oops, something went wrong.
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.