grid refresh and custom adaptor as component

I'm using blazor server and your documentation page 
I'd like to use only one custom adaptor as a component to handle all the CRUD operations o my entities and everything is working fine in the database but I can't reflect the update/insert/delete operations in the grid.
I tried to use the Refresh method in ActionBegin but the grid is not refreshed
What am I doing wrong ?

<SfGrid ID="Grid" @ref="gridmeteo" TValue="Settiman" Toolbar="@(new List<string>() { "Add", "Edit", "Delete" })">
                <SfDataManager Adaptor="Adaptors.CustomAdaptor">
                    <CustomAdaptorComponent T="Settiman" Details="DatiMeteo"></CustomAdaptorComponent>
                </SfDataManager>
                <GridEvents OnActionFailure="@Actionfailure" OnActionBegin="@ActionBegin" OnToolbarClick="ToolbarClick" TValue="Settiman"></GridEvents>
                <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog" ShowDeleteConfirmDialog="true" />
                <GridColumns>
                    <GridColumn Field=data HeaderText="Data" Width="120" Format="dd/MM/yyyy" IsPrimaryKey="true" DefaultValue="DateTime.Now"></GridColumn>
                    <GridColumn Field=anno HeaderText="Anno" AllowAdding="false" AllowEditing="false"></GridColumn>
                    <GridColumn Field=settimana HeaderText="Settimana"></GridColumn>
                    <GridColumn Field=cond_meteo HeaderText="Cond.Meteo" AutoFit="true"></GridColumn>
                </GridColumns>
 </SfGrid>


@code {
    public List<Settiman> DatiMeteo { get; set; }
    SfGrid<Settiman> gridmeteo;

    protected override void OnInitialized()
    {
        DatiMeteo = conset.GetSettimanlist();
    }

    public async Task ActionBegin(ActionEventArgs<Settiman> args)
    {

        if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
            gridmeteo.Refresh();
     }     
}

Attachment: CustomAdaptorComponent_cda07ea1.zip

3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team February 15, 2021 11:45 AM UTC

Hi Walter, 

Greetings from Syncfusion support. 

Based on your requirement, we have prepared a sample in which we are unable to reproduce the reported problem. Please refer the below validated sample for your reference. 


Note: Please change the connection string in OrderContext.cs to run the sample. 

Also please ensure whether you are getting the updated datasource in the Read method of custom Adaptor after the CRUD operation. 

    public override object Read(DataManagerRequest dm, string key = null) 
    { 
        IEnumerable<T> DataSource = (IEnumerable<T>)Details; 
//Ensure here whther you are getting the updated datasource after performing CRUD operation. 
   } 

Regards, 
Jeevakanth SP. 


Marked as answer

WM Walter Martin February 15, 2021 04:58 PM UTC

Ops, I found out that I forgot to use all these instructions in my customadaptor component

Orders.Insert(0, value as Order);

Orders.Remove(Orders.Where(or => or.OrderID == int.Parse(value.ToString())).FirstOrDefault());

...

so I only applied the modifications in the database.
Is there any other way to do this job automatically ? I mean is there any option to simply notify the datagrid that the object has been modified or added or deleted ?
Every CRUD operation have a return value statement at the end but which procedure or event can use this returned value ?



JP Jeevakanth Palaniappan Syncfusion Team February 16, 2021 08:30 AM UTC

Hi Walter, 

We would like to inform you that the below codes are necessary to perform CRUD operations using Custom Adaptor. 

Orders.Insert(0, value as Order); 

Orders.Remove(Orders.Where(or => or.OrderID == int.Parse(value.ToString())).FirstOrDefault()); 

Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon