Grid will refesh on Add but not on Update

Hi,

I am doing an Add and Updates to the database, but the grid will only refresh on the Add event, not on the Update event. The grid is inside a dialog box. Have tried Grid Refresh, StateHasChanged and even remove the grid and showed it again. The data gets to the database. I have more than 30 similar forms, and all of them have the same problem.


I tried to attach a file, but it won't let me, so here is my code:

---------------------------------

<SfDialog Width="50%" ShowCloseIcon="false" @bind-Visible="@bitRateShow">

    <DialogTemplates>

        <Content>

            <iGHIAS_Web.Pages.Shared.SubHeader SubHeaderText="Modifier - Rates" />


            <div class="div-content">

                <div class="div-controls">

                    <SfDatePicker ID="dtEffDate" CssClass="e-custom e-custom-150" TValue="DateTime" FloatLabelType="@FloatLabelType.Auto" @bind-Value="@mod.ModifierRateEffDate" Placeholder="Effective Date"></SfDatePicker>

                    <SfNumericTextBox ID="txtPercent" CssClass="e-custom e-custom-125" FloatLabelType="@FloatLabelType.Auto" Format="p2" @bind-Value="@mod.ModifierRatePercent" Placeholder="Percent" Max=1 Min=0 Step=0.01></SfNumericTextBox>

                    <SfNumericTextBox ID="txtAmount" CssClass="e-custom e-custom-125" FloatLabelType="@FloatLabelType.Auto" Format="c2" @bind-Value="@mod.ModifierRateAmountMinimum" Placeholder="Minimum Amount"></SfNumericTextBox>

                    <SfCheckBox ID="chkRateStatus" CssClass="e-custom-chk" Label="Active" @bind-Checked="@mod.ModifierRateStatus"></SfCheckBox>

                    <SfButton ID="btnRateAdd" @onclick="fnOnAdd" IsPrimary="false" CssClass="e-btn-custom" Content="@strAddUpdate"></SfButton>

                    <SfButton ID="btnRateCancel" @onclick="fnOnCancel" IsPrimary="false" CssClass="e-btn-custom" Disabled="blCancel">Cancel</SfButton>

                 </div>

            </div>


            @if (showGrid)

            {

            <div class="div-grid">

                <SfGrid ID="grdRates" @ref="gridObj" DataSource="@tblData" AllowPaging="true" AllowSorting="true" AllowResizing="true" AllowReordering="true">

                    <GridPageSettings PageSize="20"></GridPageSettings>

                    <GridEvents CommandClicked="OnCommandClicked" TValue="tbModifierRate"></GridEvents>

                    <GridColumns>

                        <GridColumn IsPrimaryKey="true" Field=@nameof(tbModifierRate.ModifierRateID)

                                    HeaderText="ID" TextAlign="@TextAlign.Left" Width="30" Visible=false>

                        </GridColumn>

                        <GridColumn Field=@nameof(tbModifierRate.ModifierID)

                                    HeaderText="ID" TextAlign="@TextAlign.Left" Width="30" Visible=false>

                        </GridColumn>

                        <GridColumn Field=@nameof(tbModifierRate.ModifierRateEffDate)

                                    HeaderText="Effective Date" TextAlign="@TextAlign.Center" Width="100" Format="d">

                        </GridColumn>

                        <GridColumn Field=@nameof(tbModifierRate.ModifierRatePercent)

                                    HeaderText="Percent" TextAlign="@TextAlign.Center" Width="50">

                        </GridColumn>

                        <GridColumn Field=@nameof(tbModifierRate.ModifierRateAmountMinimum)

                                    HeaderText="Minimum Amount" TextAlign="@TextAlign.Center" Width="60">

                        </GridColumn>

                        <GridColumn Field=@nameof(tbModifierRate.ModifierRateStatus)

                                    HeaderText="Active" TextAlign="@TextAlign.Center" Width="50">

                        </GridColumn>

                        <GridColumn HeaderText="" TextAlign="TextAlign.Center" Width="50">

                            <GridCommandColumns>

                                <GridCommandColumn Type=CommandButtonType.Edit ButtonOption="@(new CommandButtonOptions() { Content = "Edit" })">

                                </GridCommandColumn>

                            </GridCommandColumns>

                        </GridColumn>

                    </GridColumns>

                </SfGrid>

            </div>

            }


        </Content>

    </DialogTemplates>

    <DialogEvents Closed="@fnOnSubClose"></DialogEvents>

    <DialogButtons>

        <DialogButton CssClass="e-btn-custom" IsPrimary="true" Content="Close" OnClick="@fnOnSubClose" />

    </DialogButtons>

</SfDialog>


@code {

    [Parameter] public EventCallback<string> OnSubClose { get; set; }

    [Parameter] public bool bitRateShow { get; set; } = true;

    [Parameter] public string strUser { get; set; } = "";

    [Parameter] public int intID { get; set; } = 0;


    //DATABSE VARIABLES

    private tbModifierRate[] tblData;

    private tbModifierRate[] tblEdit;

    private tbModifierRate mod = new tbModifierRate();

    SfGrid<tbModifierRate> gridObj;


    //CANCEL VARIABLES

    private int intEditID = 0;

    private bool blCancel = true;

    private string strAddUpdate = "Add";


    bool showGrid { get; set; } = true;


    protected override void OnInitialized()

    {

        fnGetData();

        fnInit();

    }


    private void fnInit()

    {

        mod.ModifierRateEffDate = DateTime.Today;

        mod.ModifierRateStatus = true;

        mod.ModifierRatePercent = 0;

        mod.ModifierRateAmountMinimum = 0;

        blCancel = true;

        strAddUpdate = "Add";

        showGrid = false;

        showGrid = true;

        StateHasChanged();

    }


    protected async Task fnGetData()

    {

        tblData = await @Service.ModifierRatesGetAsync(intID);

    }


    private async Task fnOnAdd()

    {

        int intResult = 0;


        if (fnFieldCheck() == 1)

        {

            return;

        }


        switch (blCancel)

        {

            case true: //ADD

                intResult = await Service.ModifierRatesCheckAsync(intID, mod);


                if (intResult == 0)

                {

                    await Service.ModifierRatesAddAsync(intID, mod, strUser);

                    fnInit();

                }

                else

                {

                    //CODE

                }


                break;


            case false: //UPDATE

                intResult = await Service.ModifierRatesUpdateAsync(intEditID, mod);


                if (intResult == 0)

                {

                    //CODE

                }

                else

                {

                    fnInit();

                }


                break;

        }


        await fnGetData();

    }


    private int fnFieldCheck()

    {

        // VERIFICA QUE LOS CAMPOS NECESARIOS NO ESTEN EN BLANCO

        int intCheck = 0;


        return intCheck;

    }


    private void fnOnCancel()

    {

        fnInit();

    }


    public async Task OnCommandClicked(CommandClickEventArgs<tbModifierRate> args)

    {

        // Get the selected Help Desk Ticket

        if (args.CommandColumn.Type == CommandButtonType.Edit)

        {

            //Open teh Edit dialog

            intEditID = args.RowData.ModifierRateID;

            tblEdit = await @Service.ModifierRatesEditAsync(intEditID);

            mod.ModifierRateAmountMinimum = tblEdit[0].ModifierRateAmountMinimum;

            mod.ModifierRatePercent = tblEdit[0].ModifierRatePercent;

            mod.ModifierRateEffDate = tblEdit[0].ModifierRateEffDate;

            mod.ModifierRateStatus = tblEdit[0].ModifierRateStatus;

            blCancel = false;

            strAddUpdate = "Update";

        }

    }


    private async Task fnOnSubClose()

    {

        bitRateShow = false;

        await OnSubClose.InvokeAsync();

    }

}

----------------------------



6 Replies

RS Renjith Singh Rajendran Syncfusion Team October 19, 2021 03:06 AM UTC

Hi Jorge, 

Greetings from Syncfusion support. 

We have analyzed the shared codes, and we could see that you have not used the Grid’s inbuilt editing feature. We could see that you have manually handled the updates in db, so we suspect that there might be some db related problems occurred when updating your db which might have caused failure. 

SO we need the following details to further proceed on this and provide you a suggestion as early as possible. Kindly get back to us with the following details to proceed further. 

  1. Share the complete details of any exception occurred in browser console when updating a record.
  2. Share the complete code definition of ModifierRatesUpdateAsync. We need to check how you are updating to db.
  3. Bind OnActionFailure event to grid, and share the details you get in the args of this event handler.
  4. Share with us a video showing the replication of the problem you are facing.
  5. If possible share with us a simple issue reproducing sample for us to validate based on your scenario.

Regards, 
Renjith R 



JT Jorge Tirado replied to Renjith Singh Rajendran October 19, 2021 03:29 AM UTC

Thanks for the reply, here is the info asked:


  1. There is no exception
  2. Code for ModifierRatesUpdateAsync:
  3.         public async Task<int> ModifierRatesUpdateAsync(int intID, tbModifierRate mod)

            {

                string sqlstr = "";

                int intOut = 0;


                SqlParameter param1 = new SqlParameter("@intTask", 4);

                SqlParameter param2 = new SqlParameter("@intID", intID);

                SqlParameter param3 = new SqlParameter("@dtEffDate", mod.ModifierRateEffDate);

                SqlParameter param4 = new SqlParameter("@numPercent", mod.ModifierRatePercent);

                SqlParameter param5 = new SqlParameter("@numAmount", mod.ModifierRateAmountMinimum);

                SqlParameter param6 = new SqlParameter("@bitStatus", mod.ModifierRateStatus);

                SqlParameter paramOut = new SqlParameter("@intOut", intOut);

                paramOut.Direction = System.Data.ParameterDirection.Output;

                sqlstr = "EXECUTE @intOut = [spModifiersRatesTasks] @intTask, @intID, @dtEffDate, @numPercent, @numAmount, @bitStatus";

                await _context.Database.ExecuteSqlRawAsync(sqlstr, param1, param2, param3, param4, param5, param6, paramOut);

                intOut = Convert.ToInt32(Convert.ToString(paramOut.Value));


                return intOut;

            }

    3. Used the OnActionFailure, but did not produce any detail since it never entered the function.

    4. The video is attached.

    5. WIll work on the code.


Attachment: Update_Video_b3d94297.zip


JT Jorge Tirado October 19, 2021 03:33 AM UTC

As you can see on the previously attached video, the update on the database works fine, but it will only show when the whole page is refreshed. Running SQL Server 2019 Std Edition.


Jorge



RS Renjith Singh Rajendran Syncfusion Team October 20, 2021 05:08 AM UTC

Hi Jorge, 

We have analyzed your shared codes and video. We tried reproducing the reported scenario, by creating a sample based on your scenario and shared codes and updating Grid data. But we could not reproduce this reported behavior with the sample created from our side. We are attaching the sample which we have tried for your reference, 

Note : A local MDF file is used in the above sample to assign and process the data. So before running the sample, please make sure the connection for this file is established and the correct connection string(local path of the MDF file in your machine) is provided in OrderContext.cs file in the application. 
 
We are suspecting that, after clicking Update button, fnGetData method is not properly fetching the updated data from your db. And as not updated data is available in tblData inside fnGetData method is causing the reported behavior from your side. 

So we suggest you to check this scenario based on the above case from your side. And if you are still facing difficulties kindly get back to us with a simple reproducing sample or if possible reproduce the behavior with the above attached sample and share with us for further analysis. 

Regards, 
Renjith R 



JT Jorge Tirado November 10, 2021 11:47 PM UTC

Just to let you know that the problem fixed with the latest update,


Thanks.



RS Renjith Singh Rajendran Syncfusion Team November 11, 2021 05:35 AM UTC

Hi Jorge, 
 
Thanks for your update. Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 


Loader.
Up arrow icon