Refresh Grid

Dear Syncfusion Team,

i have a problem with refresh the Grid. The record has been successfully removed from the database, but is not reflected in the grid unless I reload the page. My Code:


<SfGrid DataSource="@Locations" AllowPaging="true" AllowSorting="true" @ref="grd">

    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Dialog"></GridEditSettings>

     <GridFilterSettings Type ="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings>

     <GridPageSettings PageCount="5" PageSize="8"></GridPageSettings>

     <GridColumns>

         <GridColumn Field=@nameof(DbLocation.Location) HeaderText="Standort" Width="auto"></GridColumn>

         <GridColumn Field=@nameof(DbLocation.Street) HeaderText="Adresse" Width="auto"></GridColumn>

         <GridColumn Field=@nameof(DbLocation.PLZ) HeaderText="Adresse" Width="auto"></GridColumn>

         <GridColumn Field=@nameof(DbLocation.City) HeaderText="Adresse" Width="auto"></GridColumn>

         <GridColumn Field=@nameof(DbLocation.TelNumber) HeaderText="Tel" Format="d" Type="ColumnType.Date" Width="auto"></GridColumn>

         <GridColumn HeaderText="" Width="90px">

                 <Template>

                @{

                     var location = (context as DbLocation);

                     <SfButton IconCss="e-icons e-edit" @onclick="(() => ShowLocation(location.Id))" ></SfButton>

                     <SfButton IconCss="e-icons e-trash" @onclick="(() => DeleteLocation(location.Id))"></SfButton>

                }

                </Template>

         </GridColumn>

    </GridColumns>

</SfGrid>


@code{

 public IQueryable<DbLocation>? Locations { get; set; }

    SfGrid<DbLocation>? grd;


    protected override async Task OnInitializedAsync()

    {

        Locations = await locationSrv.GetLocationsAsync();

    }


public void ShowLocation(Guid Id)

    {

        nav.NavigateTo($"/locations/edit/{Id}");

    }


    void DeleteLocation(Guid Id)

    {

        locationSrv.DeleteLocationService(Id);

        this.grd.Refresh();

    }

}


And here is the DeleteLocationService Methode from  class LocationService:


public void DeleteLocationService(Guid locationId)

{

                var loc = Ctx.Locations.Find(locationId);

                Ctx.Locations.Remove(loc);

                 Ctx.SaveChanges();

 }


Can you help me ?



3 Replies

SP Sarveswaran Palani Syncfusion Team November 1, 2022 05:44 PM UTC

Hi Artur,


Based on your query, mostly we suggest you to call Refresh method to overcome the issue, but still if you are facing an issue, again bind data to the data source property to resolve an issue.


Kindly get back to us, if you have any further queries.


Regards,

Sarveswaran PK



AZ Artur Zigel November 9, 2022 07:48 AM UTC

Dear Syncfusion-Team,


i tried the Refresh method but it didn't work. Can you send me an example ?


Best Regards,

Artur Zigel



SP Sarveswaran Palani Syncfusion Team November 16, 2022 05:03 AM UTC

Hi Artur,

From your query, we suspect that you’re facing issue in refreshing the Grid. Generally, we suggest to call Refresh method or bind data to the datasource property on Initialization process. There isn't any another way to resolve this issue. Kindly share the screenshot/video demo of an issue or share issue reproducible simple runnable sample to us. It’ll will be very helpful for us to validate the reported query at our end and provide the solution as early as possible


Regards,

Sarveswaran PK


Loader.
Up arrow icon