SfGrid doesnt update after edit or delete with dapper

Hello,

I have searched the forum by myself hopping to find how to fix my problem, but without sucess.
So I'm sorry if this has already been asked....

I have found one thread where you explain how to use the edit feature of the ZsGrid.
And here is what I wrote :

        <SfGrid ID="gridContactEvent" Width="auto" Height="200px" DataSource="@contactEvent" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
            <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal" ShowConfirmDialog="true" ShowDeleteConfirmDialog="true"></GridEditSettings>
            <GridEvents OnActionBegin="ActionBeginHandler" OnActionComplete="ActionCompleteHandler" RowSelected="RowSelecthandler" TValue="ContactEventModel"></GridEvents>

            <GridColumns>
                <!--                <GridColumn Field=@nameof(ContactEventModel.ID_CONTACT) HeaderText="ID" Width="70"> </GridColumn>-->
                <GridColumn Field=@nameof(ContactEventModel.Date_appel) Format="d" Type="ColumnType.Date" HeaderText="Date Appel" Width="100"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Remarques) HeaderText="Remarques" Width="400"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Durée) HeaderText="Duree" Width="80"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Responsable) HeaderText="Responsable" Width="80"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Type) HeaderText="Type" Width="80"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Cible) HeaderText="Cible" Width="80"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Cible_Nom) HeaderText="Cible_Nom" Width="80"> </GridColumn>
                <GridColumn Field=@nameof(ContactEventModel.Action) HeaderText="Action" Width="80"> </GridColumn>
            </GridColumns>
        </SfGrid>


AND : 

    public async Task ActionBeginHandler(ActionEventArgs<ContactEventModel> arg)
    {

        if (arg.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
        {
            if (arg.Action == "Add")
            {
                arg.Data.ID_CONTACT = CurContact.ID_CONTACT;
                await _db.InsertContactEvent(arg.Data);
                System.Console.WriteLine("Insert.");
            }
            else if (arg.Action == "Edit")
            {
                await _db.UpdateContactEvent(arg.Data);
                System.Console.WriteLine("Update.");
            }
        }
        if (arg.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Delete))
        {
            await _db.DeleteContactEvent(arg.Data);
        }
    }

Adding new items works perfectly.

Problem 1
Editing and Item does change the item in the database but the edit line stay as it is with the UPDATE and CANCEL button, when i clic on update it saves the change in the data base but nothing happens, i have to push CANCEL to end the editing phase and move from my reccord and come back to see the change

Problem 2
Deleting does delete the item in the database but the list doesnt show the change, i have to move from my reccord and come back to it to see the change

Thank you in advance for your help.

David


3 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team November 2, 2020 05:54 AM UTC

Hi David,  
 
Thanks for contacting Syncfusion support.  
 
Query: “SfGrid doesnt update after edit or delete with dapper” && “when i clic on update it saves the change in the data base but nothing happens, 
 
We have analyzed your query and we understand that you are facing issue while performing CRUD operation in Grid using Dapper. From your code example, we found that you have updated the changes in your database using OnActionBegin event of grid and updated changes are not reflected in Grid.  
 
To resolve the issue we suggest you to fetch the updated data from your database in the OnActionComplete event of Grid when RequestType is Save.  Refer the below code example. 
 
<SfGrid ID="gridContactEvent" Width="auto" Height="200px" DataSource="@contactEvent" Toolbar="@(new List<string>() { "Add""Edit""Delete""Update""Cancel" })"> 
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal" ShowConfirmDialog="true" ShowDeleteConfirmDialog="true"></GridEditSettings> 
    <GridEvents OnActionBegin="ActionBeginHandler" OnActionComplete="ActionCompleteHandler" RowSelected="RowSelecthandler" TValue="ContactEventModel"></GridEvents>  
    <GridColumns> 
        <!--                <GridColumn Field=@nameof(ContactEventModel.ID_CONTACT) HeaderText="ID" Width="70"> </GridColumn>--> 
        <GridColumn Field=@nameof(ContactEventModel.Date_appel) Format="d" Type="ColumnType.Date" HeaderText="Date Appel" Width="100"> </GridColumn> 
        <GridColumn Field=@nameof(ContactEventModel.Remarques) HeaderText="Remarques" Width="400"> </GridColumn> 
        <GridColumn Field=@nameof(ContactEventModel.Durée) HeaderText="Duree" Width="80"> </GridColumn> 
. . . . .  
    </GridColumns> 
</SfGrid> 
  
@code { 
    public string _state; 
    public async Task ActionCompleteHandler(ActionEventArgs<ContactEventModel> args) 
    { 
        if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save)) 
        { 
            // fetch and bind updated data from your database to Grid.  
            contactEvent = // bind updated list to grid datasource. 
        }  
    } 
 
From your code example we found that you have not enabled PrimaryKey column in Grid. CRUD operation in Grid will take place based on PrimaryKey column whose value is unique. IsPrimaryKey property of GridColumns is used to define the primary key. So kindly define the IsPrimaryKey property to any one of the available column whose value is unique.  
 
Refer our UG documentation for your reference 
 
 
Kindly get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Marked as answer

DA David November 19, 2020 09:38 PM UTC

Sorry for the long time....
It took me a while before I could get back to this.
I figured out how to make it works properly.
Thanks for your help !

David


RS Renjith Singh Rajendran Syncfusion Team November 20, 2020 01:33 PM UTC

Hi David, 

Thanks for your update. 

We are glad to hear that your requirement has been achieved.  

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Loader.
Up arrow icon