I cannot refresh the grid after updating values.

Hello, i have a problem with the grid. I am using the dialog edit and when i want to edit a record the grid does not show the new value. I tried with GridMP.Refresh(); but it does nothing. The only way i find to do this is to fill the dataSource again but if i have thousands of records this is not viable. Here is the code i am using:


.razor:
<SfGrid  @ref="GridMP" DataSource="@listaAbastMP" Toolbar="@ToolbaritemsMP">
                        <GridEvents OnToolbarClick="@ClickHandlerMP" OnActionBegin="ActionBeginMP" TValue="ModeloAbastecimiento"></GridEvents>
                        <GridEditSettings AllowDeleting="true" AllowEditing="true" Mode="@EditMode.Dialog" Dialog="DialogParams">
                            <Template>
                                @{
                                    var MP = (context as ModeloAbastecimiento);
                                    <div>
                                        <div class="form-row">
                                            <div class="form-group col-md-6">
                                                <label class="e-float-text e-label-top">Producto:</label>
                                                <br />
                                                <SfTextBox ID="CG_PROD" @bind-Value="@(MP.CG_MAT)" Enabled="false"></SfTextBox>
                                            </div>
                                            <div class="form-group col-md-6">
                                                <label class="e-float-text e-label-top">Stock a Comprar:</label>
                                                <br />
                                                <SfNumericTextBox ID="ACOMPRAR" Format="N2" @bind-Value="@(MP.ACOMPRAR)" Enabled="true"></SfNumericTextBox>
                                            </div>
                                        </div>
                                    </div>
                                }
                            </Template>
                        </GridEditSettings>
                        <GridColumns>
                            <GridColumn Field=@nameof(ModeloAbastecimiento.CG_MAT) HeaderText="Producto" Visible="Disabled" Width="90px"></GridColumn>
                            <GridColumn Field=@nameof(ModeloAbastecimiento.ACOMPRAR) Format="N2" HeaderText="Stock a Comprar" Visible="Enabled" Width="130px"></GridColumn>
                        </GridColumns>
                    </SfGrid>
.razor.cs:
public async Task ActionBeginMP(ActionEventArgs<ModeloAbastecimiento> args)
        {
            if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
            {
                HttpResponseMessage response;
                response = await Http.PutAsJsonAsync($"api/Abastecimiento/PutAbMP/{args.Data.CG_MAT}", args.Data);
                listaAbastMP = await Http.GetFromJsonAsync<List<ModeloAbastecimiento>>("api/Abastecimiento/AbastecimientoMPX");
                GridMP.Refresh();
            }
        }
Controller:
// PUT: api/Abastecimiento/PutAbMP/{id}
        [HttpPut("PutAbMP/{id}")]
        public async Task<ActionResult<List<ModeloAbastecimiento>>> PutAbMP(string id, ModeloAbastecimiento Ab)
        {
            string xCg_mat = Ab.CG_MAT;
            string xValor = Ab.ACOMPRAR.ToString();
            // Reemplaza "," por "." para grabar en el SQL
            xValor = Convert.ToDouble(xValor.Replace(",", ".")).ToString();
            ConexionSQL xConexionSQL = new ConexionSQL(CadenaConexionSQL);
            string xSQLcommandString = "UPDATE NET_Temp_Abastecimiento SET ACOMPRAR = " + xValor + " WHERE Cg_mat='" + xCg_mat + "'";
            xConexionSQL.EjecutarSQLNonQuery(xSQLcommandString);

            return NoContent();
        }

// GET: api/Abastecimiento/AbastecimientoMPX
        [HttpGet("AbastecimientoMPX")]
        public List<ModeloAbastecimiento> AbastecimientoMPX()
        {
            try
            {
                ConexionSQL xConexionSQL = new ConexionSQL(CadenaConexionSQL);
                xConexionSQL = new ConexionSQL(CadenaConexionSQL);
                string xSQLCommandString = ("SELECT CG_MAT, ACOMPRAR FROM NET_Temp_Abastecimiento WHERE CG_ORDEN = 4");
                dbAbastecimientoMP = xConexionSQL.EjecutarSQL(xSQLCommandString);

                List<ModeloAbastecimiento> xLista = dbAbastecimientoMP.AsEnumerable().Select(m => new ModeloAbastecimiento()
                {
                    CG_MAT = m.Field<string>("CG_MAT"),
                    ACOMPRAR = m.Field<decimal?>("ACOMPRAR"),
                }).ToList<ModeloAbastecimiento>();
                return xLista;
            }
            catch (Exception ex)
            {
                return new List<ModeloAbastecimiento>();
            }
        }

1 Reply 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team January 26, 2021 05:10 AM UTC

Hi Matias, 

Greetings from Syncfusion.  

We have validated your query with the provided code snippets. From your code snippets, you have not defined PrimaryKey for any one of the columns in the Grid. Editing feature requires a primary key column for CRUD operations. 

To define the primary key, set IsPrimaryKey to true in particular column whose value is unique. 
 
<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" ValidationRules="@(new ValidationRules{ Required=true})" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        . . . 
    </GridColumns> 
</SfGrid> 

Reference: 

If you are still facing the problem, please let us know. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon