We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

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 12:44 PM

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 02:48 AM

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 12:03 AM

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.
Live Chat Icon For mobile
Up arrow icon