I have the multiselect inside the in-place editor to assign user roles:
<SfInPlaceEditor Type="Syncfusion.Blazor.InPlaceEditor.InputType.MultiSelect" TValue="string[]" Value="@SelectedUserRoles"
Mode="RenderMode.Inline" CssClass="w-80" EmptyText="-" ShowButtons="true" ActionOnBlur="ActionBlur.Cancel" SubmitOnEnter="true">
<InPlaceEditorEvents TValue="string[]" OnActionBegin="@(() => OnRoleConfirm())" />
<EditorComponent>
<SfMultiSelect TValue="string[]" TItem="AutoCompleteItem" AllowCustomValue="false"
@bind-Value="@SelectedUserRoles" DataSource="@CouldAssignRoles"
ShowClearButton="false" Mode="@VisualMode.Box" ShowDropDownIcon="true" AllowFiltering="false">
<MultiSelectFieldSettings Text="@nameof(AutoCompleteItem.ShowThis)" Value="@nameof(AutoCompleteItem.Result)" />
<MultiSelectEvents TValue="string[]" TItem="AutoCompleteItem" OnValueSelect="@OnChipSelected" />
</SfMultiSelect>
</EditorComponent>
</SfInPlaceEditor>
Depending on selected role the list of already selected roles should be changed:
private void OnChipSelected(SelectEventArgs<AutoCompleteItem> args)
{
SelectedUserRoles = CouldAssignRoles.FilterAvailableRoles(SelectedUserRoles, args.ItemData.Result);
}
When the selection is finished, it could be saved:
private async Task OnRoleConfirm()
{
List<string> AddRoles = SelectedUserRoles.Where(r => !UserRoles.Contains(r)).ToList();
List<string> RemoveRoles = UserRoles.Where(r => !SelectedUserRoles.Contains(r)).ToList();
if (AddRoles.Count > 0 || RemoveRoles.Count > 0)
{
ApplicationUser UmUser = await UserManager.FindByIdAsync(ProfileUser.Id).ConfigureAwait(false);
if (RemoveRoles.Count > 0)
await UserManager.RemoveFromRolesAsync(UmUser, RemoveRoles).ConfigureAwait(false);
if (AddRoles.Count > 0)
await UserManager.AddToRolesAsync(UmUser, AddRoles).ConfigureAwait(false);
NavigationManager.NavigateTo($"Account/Profile/{ProfileUser.UserName}", true);
}
}
Everything works well except OnChipSelected. It updates binded SelectedUserRoles, but the viewed list is not changed and InvokeAsync(StateHasChanged) does not help. How can I enforce the change of shown value?
|
<SfInPlaceEditor Type="Syncfusion.Blazor.InPlaceEditor.InputType.MultiSelect" TValue="string[]" Value="@MultiValue"
Mode="RenderMode.Inline" CssClass="w-80" EmptyText="-" ShowButtons="true" ActionOnBlur="ActionBlur.Cancel" SubmitOnEnter="true">
<InPlaceEditorEvents TValue="string[]" OnActionBegin="@(() => OnRoleConfirm())" />
<EditorComponent>
<SfMultiSelect TValue="string[]" TItem="Countries" AllowCustomValue="false" ChangeOnBlur="false"
@bind-Value="@MultiValue" DataSource="@Country"
ShowClearButton="false" Mode="@VisualMode.Box" ShowDropDownIcon="true" AllowFiltering="false"> <MultiSelectFieldSettings Text="Name" Value="Code" /> <MultiSelectEvents TValue="string[]" TItem="Countries" ValueChange="@OnChipSelected" />
</SfMultiSelect>
</EditorComponent> </SfInPlaceEditor>@code {
private void OnChipSelected(Syncfusion.Blazor.DropDowns.MultiSelectChangeEventArgs<string[]> args)
{
//You can call your method here.
} } |
Thank you, everything is work. Only one detail - I have ShowButtons="true" in In-Place Editor, but buttons are not shown anyway.