Hi
I'm new to Blazor and trying to write a Blazor WebAssembly app in .NET 6. I've attached the code of one of my pages.
The app reads in the data that populates the grid but it isn't displayed when the page is displayed. I've added a button that refreshes the grid. I have to press it twice to display the data. Then everything works perfectly.
If I use WebAPI to bind to the grid the data is displayed when the page is displayed, but the paging and search options don't work.
I cannot find a way to make everything work when the page is first displayed.
Can you help please?
Regards
Brian
Hi Brian,
Greetings from Syncfusion
Query: “The app reads in the data that populates the grid but it isn't displayed when the page is displayed. I've added a button that refreshes the grid. I have to press it twice to display the data. Then everything works perfectly.”
We have prepared an simple sample as per your shared reference. We suspect that the Data is not fetched properly from the service so the reported issue occurs. Kindly ensure once whether the Data is fetched properly and update the below details it will be very helpful for us to validate the reported issue at our end.
The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.
@using Syncfusion.Blazor.Grids @inject WeatherForecastService ForecastService @using SfGridPager.Data
<SfGrid DataSource="@forecasts" EnableVirtualization="true" Height="400" RowHeight="38">
</SfGrid>
@code { private WeatherForecast[] forecasts;
protected override async Task OnInitializedAsync() { forecasts = await ForecastService.GetForecastAsync(DateTime.Now); } }
|
Query: “If I use WebAPI to bind to the grid the data is displayed when the page is displayed, but the paging and search options don't work.”
Data operations and CRUD operations need to be handled on the controller part for the WebApi Adaptor.
Please let us know if you have any concerns.
Regards,
Monisha
Hi Monisha
Thanks for your reply. I've attached some screen shots and two razor files.
I have two razor files, CostCentres and Funding, which both have problems with a datagrid. The problems in one aren't the same as the problems in the other. I'm trying to find a way to merge these files so that all the problems go away.
There are seven screen shots as follows:
Hi Brian,
We have attached an working sample of CRUD with WebApi. Kindly check the attached sample for your reference.
Also in your shared code( Fundings.razor) we could wee that you have used both the DataSource property and SfDataManager in your code. We suggest you to use any one of the above at your end either Datasource or SfDataManger.
Also after fetching the datasource try to assign datasource once again to the Grid DataSource property.
protected async void InitData() { var response = await client.GetAsync($"api/CostCentre"); response.EnsureSuccessStatusCode(); CostCenters = await response.Content.ReadFromJsonAsync<List<CostCentre>>(); //Assign datasource once again here DefaultGrid.Datasource = CostCenters; } |
Please let us know if you have any concerns.
Regards,
Monisha
Hi Monisha
Thanks for your help.
I made changes and my code is working as I want it to work.
Thank You
Brian
Hi Brian,
Welcome. We are glad to hear that the reported query has been resolved. Kindly get back to us if you have further queries. As always we will be happy to assist you.
Regards,
Monisha