Correct way to binding Editforms
I have a problem changing values in a new row in code behind. This is my Sfgrid:
<SfGrid @ref="GridInsumos" AllowPaging="true" DataSource="@LPartidasGrid" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })" style="min-height:80px;">
<GridEvents OnActionBegin="OnActionBegin" OnActionComplete="OnActionComplete" TValue="PartidaStock"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(PartidaStock.Partida) HeaderText="Trazabilidad" EditType="EditType.DropDownEdit" Width="150" IsPrimaryKey="true">
<EditTemplate Context="Partida">
<SfDropDownList ID="Trazabilidad" Placeholder="Trazabilidad" TItem="PartidaStock" TValue="string" @bind-Value="@((Partida as PartidaStock).Partida)" DataSource="@LPartidasInsumos" AllowFiltering="true" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains">
<DropDownListFieldSettings Text="Partida" Value="SelectorInsumo"></DropDownListFieldSettings>
<DropDownListEvents ValueChange="OnChangePartida" TItem="PartidaStock" TValue="string"></DropDownListEvents>
</SfDropDownList>
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(PartidaStock.CantidadStock) HeaderText="Stock" Width="200">
<EditTemplate Context="detalleStock">
@{
//Insumo = (detalleInsumo as PartidaStock).DescArticulo;
<SfNumericTextBox @ref="TxtBoxStock" ID="Stock" @bind-Value="@((detalleStock as PartidaStock).CantidadStock)" ></SfNumericTextBox>
}
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(PartidaStock.DescArticulo) HeaderText="Insumo" Width="200">
<EditTemplate Context="detalleInsumo">
@{
//Insumo = (detalleInsumo as PartidaStock).DescArticulo;
<SfTextBox @ref="TxtBox" ID="Insumo" @bind-Value="@((detalleInsumo as PartidaStock).DescArticulo)" ></SfTextBox>
}
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(PartidaStock.CantidadTarea) HeaderText="Cantidad" Format="N2" Width="200">
<EditTemplate Context="detalleCantidad">
@{
//Qtt = (detalleCantidad as PartidaStock).CantidadTarea;
<SfNumericTextBox TValue="decimal?" @ref="TxtBoxQtt" ID="Cantidad" @bind-Value="@((detalleCantidad as PartidaStock).CantidadTarea)"></SfNumericTextBox>
}
</EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid>
When I change the first cell, fire OnChangePartida and in this point, I complete some cells in code behind.
public async void OnChangePartida(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, PartidaStock> args)
{
Partida = args.ItemData.Partida;
TxtBox.Value = args.ItemData.CodigoArticulo + " " + args.ItemData.DescArticulo + " (Stock Disponible:" + Math.Round((decimal)args.ItemData.CantidadStock, 2) + ")";
Insumo = TxtBox.Value;
TxtBoxStock.Value = args.ItemData.CantidadStock;
GUIDPartidaStock = args.ItemData.GUIDPartidaStock;
TxtBox.FocusAsync();
TxtBoxStock.FocusIn();
this.StateHasChanged();
GridInsumos.CallStateHasChanged();
}
The problem is when I fill the last cell, i have a customvalidator in the class, and only arrive this cell, all of the object is empty.
If I fill all row manualy, works great. What i'm missing?
Thanks for your time!
Hi Guillermo,
Greetings from Syncfusion support.
We suspect that your requirement is to update the other column values while changing the value in the dropdown. If so we suggest you to use the context to update the other column value.
For example in the below code we have passed the context value along with the ValueChange event argument and change the required column value in the context. So that it will reflect properly on update. Kindly check the below attached code snippet for your reference.
|
<SfGrid @ref="GridInsumos" AllowPaging="true" DataSource="@LPartidasGrid" ShowColumnChooser="true" Toolbar="@(new List<string>() { "Add","Edit","Delete","Update","Cancel" })" style="min-height:80px;">
<GridEvents OnActionBegin="OnActionBegin" OnActionComplete="OnActionComplete" TValue="PartidaStock"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(PartidaStock.Partida) HeaderText="Trazabilidad" EditType="EditType.DropDownEdit" Width="150" IsPrimaryKey="true">
<EditTemplate Context="Partida"> @{ var context = (Partida as PartidaStock); <SfDropDownList ID="Trazabilidad" Placeholder="Trazabilidad" TItem="PartidaStock" TValue="string" @bind-Value="@((Partida as PartidaStock).Partida)" DataSource="@LPartidasInsumos" AllowFiltering="true" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains">
<DropDownListFieldSettings Text="Partida" Value="SelectorInsumo"></DropDownListFieldSettings>
<DropDownListEvents ValueChange="((args)=>OnChangePartida(args,context )" TItem="PartidaStock" TValue="string"></DropDownListEvents>
</SfDropDownList> } </EditTemplate>
</GridColumn>
</GridColumns>
</SfGrid> @code{ public async void OnChangePartida(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string, PartidaStock> args, PartidaStock val)
{ // Now you can access the context value here in "val". Kinldy try making changes in the context. Partida = args.ItemData.Partida;
TxtBox.Value = args.ItemData.CodigoArticulo + " " + args.ItemData.DescArticulo + " (Stock Disponible:" + Math.Round((decimal)args.ItemData.CantidadStock, 2) + ")";
Insumo = TxtBox.Value;
TxtBoxStock.Value = args.ItemData.CantidadStock;
GUIDPartidaStock = args.ItemData.GUIDPartidaStock;
TxtBox.FocusAsync();
TxtBoxStock.FocusIn();
this.StateHasChanged();
GridInsumos.CallStateHasChanged(); } } |
If you still face difficulties then kindly get back to us with an simple issue reproduceable sample and video demonstration of the issue. It would be very helpful for us to validate the reported issue at our end.
Regards,
Monisha
Attachment: BlazorApp1_47eee111.zip
- 1 Reply
- 2 Participants
-
GU Guillermo
- Aug 17, 2023 04:26 PM UTC
- Aug 18, 2023 12:22 PM UTC