Hi team,
There is an use case: I would like to implement a three-hierarchy In-place Editor with DropDownList to allow my clients to select some value, Vender-Brand-Product for example, I have referenced the official DropDownList Cascading sample, but it's somehow unfit to my case: I need to update the second and third level's DataSource dynamically from server, not from a local Query, since the second and third level contain huge data. So I build a structure like this and expect it could work:
private SfDropDownList<int, StandardDto> VenderModel = new SfDropDownList<int, StandardDto>
{
Fields = new FieldSettingsModel {Text = "Name", Value = "Id"},
DataSource = new List<StandardDto>(),
};
private SfDropDownList<int, StandardDto> BrandModel = new SfDropDownList<int, StandardDto>
{
Fields = new FieldSettingsModel {Text = "Name", Value = "Id"},
DataSource = new List<StandardDto>()
};
private SfDropDownList<int, StandardDto> ProductModel = new SfDropDownList<int, StandardDto>
{
Fields = new FieldSettingsModel {Text = "Name", Value = "Id"},
DataSource = new List<StandardDto>()
};
and initialize the first level in OnInitializedAsync:
protected override async Task OnInitializedAsync()
{
VenderModel.DataSource = (await _appService.GetVenderListAsync()).ToList();
await base.OnInitializedAsync();
}
the View is:
<div class="form-group row">
<label class="col-sm-2">Vender</label>
<div class="col-sm-10">
<SfInPlaceEditor Name="Vender" Mode="RenderMode.Inline" Type="InputType.DropDownList" @bind-Value="Selected.Vender.Id" Model="VenderModel" ShowButtons="false" EmptyText="">
<InPlaceEditorEvents OnActionBegin="OnVenderChange" TValue="int"></InPlaceEditorEvents>
</SfInPlaceEditor>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">Brand</label>
<div class="col-sm-10">
<SfInPlaceEditor @ref="_brandEditor" Name="Brand" Mode="RenderMode.Inline" Type="InputType.DropDownList" @bind-Value="Selected.Brand.Id" Model="BrandModel" ShowButtons="false" EmptyText="">
<InPlaceEditorEvents OnActionBegin="OnBrandChange" TValue="int"></InPlaceEditorEvents>
</SfInPlaceEditor>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2">Product</label>
<div class="col-sm-10">
<SfInPlaceEditor @ref="_productEditor" Name="Product" Mode="RenderMode.Inline" Type="InputType.DropDownList" @bind-Value="Selected.Product.Id" Model="ProductModel" ShowButtons="false" EmptyText="">
<InPlaceEditorEvents OnActionBegin="OnProductChange" TValue="int"></InPlaceEditorEvents>
</SfInPlaceEditor>
</div>
</div>
and I linked three level through (the third level omitted for simplicity):
private async Task OnVenderChange(ActionBeginEventArgs args)
{
InPlaceEditorArgs inPlaceEditorArgs = args.GetInPlaceEditorArgs(); //this is a self-made extension method to get changed name and value
if (!inPlaceEditorArgs.Value.IsNullOrEmpty())
{
BrandModel.DataSource = (await _appService.GetBrandListAsync(int.Parse(inPlaceEditorArgs.Value))).ToList();
//whatever way I used bellow, the second level never updated, it keeped an empty list.
_brandEditor.Refresh();
BrandModel.Refresh();
await InvokeAsync(StateHasChanged);
}
}
But of course it didn't work. So I think there maybe something wrong when I established this, could you please supply a sample to show how to deal with this kind of server-update cascading requirement?
Thanks.