Replies: 1 comment 2 replies
-
I fixed this by changing my SelectedCityChanged implementation to the following: `private void SelectedCityChanged(CellEditContext context, string value)
By casting the value before assigning to CellValue, it fixes the model conversion problem that I was facing. IMO a numeric string ought to work, so worth investigating by the dev team :) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I have placed an autocomplete as the edit template inside a datagrid. For context, I have a Patient model for which I am trying to specify the City. Here is the autocomplete markup:
<DataGridColumn Field="@nameof(Patient.CityId)" Caption="City" Editable Filterable="false"> <DisplayTemplate> <Span>@context.CityName</Span> </DisplayTemplate> <EditTemplate> <Autocomplete TItem="City" TValue="string" Data="@cities" TextField="@((City x) => x.Name)" ValueField="@((City x) => x.Id.ToString())" SelectedValue="@(context.CellValue.ToString())" SelectedValueChanged="@((value) => SelectedCityChanged(context, value))" Placeholder="Search..." Filter="AutocompleteFilter.StartsWith" FreeTyping CustomFilter="@(( item, searchValue ) => item.Name.IndexOf( searchValue, 0, StringComparison.CurrentCultureIgnoreCase ) >= 0 )"> <NotFoundContent Context="autoContext"> Sorry... @autoContext was not found </NotFoundContent> <ItemContent Context="autoContext"> <Div Flex="Flex.InlineFlex.JustifyContent.Between" Width="Width.Is100"> <Div Margin="Margin.Is2.FromBottom">@autoContext.Text</Div> <Small>@autoContext.Item.StateName, @autoContext.Item.CountryName</Small> </Div> </ItemContent> </Autocomplete> </EditTemplate> </DataGridColumn>
The SelectedValueChanged event handler is as follows:
`private void SelectedCityChanged(CellEditContext context, string value)
{
if (value == null)
value = string.Empty;
Once I Save the changes in my datagrid, I expect the following methods to execute correctly:
void OnRowUpdating (CancellableRowChange<Patient, Dictionary<string, object>> c) { validateInsertOrUpdate(c); } async Task OnRowUpdated (SavedRowItem<Patient, Dictionary<string, object>> c) { await AlertService.ProcessMessage(await PatientService.Update(c.Item), c.Item, CrudOperationType.Updated); StateHasChanged(); }
However, I get the following error after OnRowUpdating successfully executes, but before OnRowUpdated is called:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Specified cast is not valid. System.InvalidCastException: Specified cast is not valid. at Blazorise.DataGrid.DataGridColumn
1[[NutritionProViewModels.Practice.Patient, NutritionProViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetValue(Patient item, Object value)at Blazorise.DataGrid.DataGrid
1.<Save>d__43[[NutritionProViewModels.Practice.Patient, NutritionProViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext() at Blazorise.DataGrid._BaseDataGridRowEdit
1.d__9[[NutritionProViewModels.Practice.Patient, NutritionProViewModels, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Blazorise.Button.ClickHandler()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)`
Can you tell me what I am doing wrong? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions