I have a Blazorise DataGrid EditTemplate such that:
<EditTemplate>
<Select TValue="int" SelectedValue="@((int)( context.CellValue ))" SelectedValueChanged="@(( v ) => context.CellValue = v)">
<SelectItem TValue="int" Value="0">All</SelectItem>
<SelectItem TValue="int" Value="1">Option 1</SelectItem>
<SelectItem TValue="int" Value="2">Option 2</SelectItem>
</Select>
</EditTemplate>
which works fine. I want to turn this into custom component I can reuse, so created the following:
SourcesEdit.razor:
<Select TValue="int" SelectedValue="@((int)( sourceId ))" SelectedValueChanged="@(( v ) => sourceId = v)">
<SelectItem TValue="int" Value="0">All</SelectItem>
<SelectItem TValue="int" Value="1">Option 1</SelectItem>
<SelectItem TValue="int" Value="2">Option 2</SelectItem>
</Select>
@code {
[Parameter]
public int sourceId { get; set; }
}
Which I call with
<EditTemplate>
<SourcesEdit sourceId="@((int)( context.CellValue ))" />
</EditTemplate>
The Select component is displayed and behaves correctly but the selection is not reflected in the grid after clicking save.
What am I doing wrong?
Here's a code sample illustrating how to create a custom component that displays a list of values (departments) for the user to select when in edit mode. The selected option is the value displayed in display mode. If you add a new employee, the selected value is the string "Select..."
EditComponent.razor
And this is how you embed the EditComponent in the
EditTemplatetemplate in the DataGrid. Copy and test...Usage: