what is the event when data are binded and loaded?

DataGrid is used to show data from large table which should be transformed to List of ExpandoObject. It takes long time, about 1-2 minutes.
All this time No records to display is shown.
Of course I preferred to show spinner while data will be prepared. Plus after table content will be shown I would like to make some data operations in table - search and row selecting.
I tried in Grid something like 
                @if (IsInitialRender)
                {
                    <SfDataManager Adaptor="Adaptors.BlazorAdaptor" Data="DataSource" />
                }
and 
    public async Task OnDataBound()
    {
        if (!IsInitialRender)
        {
            IsInitialRender = true;
......
        }
    }

Also I tried to use OnAfterRender, but data are not ready before this events yet.

7 Replies

RN Rahul Narayanasamy Syncfusion Team May 19, 2020 03:31 PM UTC

Hi Stanislav, 

Greetings from Syncfusion. 

Query: I preferred to show spinner while data will be prepared 

We have validated your query and you want to show the spinner before the data is bound to the Grid. You can achieve your requirement by calling the ShowSpinner and HideSpinner methods and Grid events. Here, we have show the spinner(called the showspinner method in DataBound event) and hided the spinner(in RoeDataBound event) while data is bound in the Grid.  

 
<SfGrid ID="Grid" @ref="Grid" DataSource="@Orders" AllowPaging="true"> 
    <GridEvents RowDataBound="RowDataBoundHandler" DataBound="DataBoundHandler" TValue="Order"></GridEvents> 
    <GridPageSettings PageSize="5"></GridPageSettings> 
    . . . 
</SfGrid> 
 
@code{ 
    SfGrid<Order> Grid { get; set; } 
    public List<Order> Orders { get; set; } 
    bool intial { get; set; } = true; 
    protected override async Task OnInitializedAsync() 
    { 
        await Task.Delay(4000); 
        Orders = Enumerable.Range(1, 75).Select(x => new Order() 
        { 
            OrderID = 1000 + x, 
            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)], 
            Freight = 2.1 * x, 
            OrderDate = DateTime.Now.AddDays(-x), 
        }).ToList(); 
    } 
 
    . . . 
    public void DataBoundHandler(object args) 
    { 
        if (intial) 
        { 
            Grid.ShowSpinner();   //show spinner 
            intial = false; 
        } 
    } 
    public void RowDataBoundHandler(RowDataBoundEventArgs<Order> args) 
    { 
        Grid.HideSpinner();   //hide spinner 
    } 
} 

For performing the data operations Search and row selection, we suggest you to use the Search method and SelectRow method of the Grid. 

Grid.SelectRow(index);   //example Grid.SelectRow(3) 
    
Grid>Search(SearchKey)   //example: Grid.Search(“alfki”) 


Please get back to us if you need further assistance. 

Regards, 
Rahul 




GI Giacomo December 26, 2021 10:48 AM UTC

Hi,

I've the similar issue , I have a blazor server page where I had to display into an sfgrid some data coming from sql server which take around 10 seconds to load from.

The problem is that when I click link page or try to access directly by url, nothing is shown (neither the sfgrid itself) until all data are loaded and displayed into the page.

The same issue is still found in your sample code which i twicked a little to add Logger to see when events are fired and rised Task.Delay from 4000 to 10000 to simulate my scenario.


Here's sample code modified :


@page "/testgridbusy"

@using Syncfusion.Blazor.Grids

@using Syncfusion.Blazor.Spinner

@using Microsoft.Extensions.Logging

@inject ILogger<TestGridBusy> logger


<SfGrid ID="Grid" @ref="Grid" DataSource="@Orders" AllowPaging="true">

    <GridEvents RowDataBound="RowDataBoundHandler" DataBound="DataBoundHandler" TValue="Order"></GridEvents>

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

</SfGrid>


@code{

    SfGrid<Order> Grid { get; set; }

    public List<Order> Orders { get; set; }

    bool intial { get; set; } = true;


    protected override async Task OnInitializedAsync()

    {

        logger.LogInformation("[{0}] Entered OnInitializedAsync()!", DateTime.Now);

        await Task.Delay(10000);

        Orders = Enumerable.Range(1, 75).Select(x => new Order()

        {

            OrderID = 1000 + x,

            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

            Freight = 2.1 * x,

            OrderDate = DateTime.Now.AddDays(-x),

        }).ToList();

    }

    public void DataBoundHandler(object args)

    {

        if (intial)

        {

            logger.LogInformation("[{0}] Entered DataBoundHandler()!", DateTime.Now);

            Grid.ShowSpinner(); //show spinner

            intial = false;

        }

    }

    public void RowDataBoundHandler(RowDataBoundEventArgs<Order> args)

    {

        Grid.HideSpinner(); //hide spinner

    }

    public class Order

    {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }

}

What I'd like to achieve is when I access sample page , it will be shown immediatly empty grid with spinning circle that should disappears when grid is populated, is it possible to do this ?

I just recorded a video to try to explain better my point : https://www.screencast.com/t/goMi3JARE


Thank you

Best Regards,

Giacomo



RN Rahul Narayanasamy Syncfusion Team December 27, 2021 02:35 PM UTC

Hi Giacomo, 

Greetings from Syncfusion. 

We are currently checking the reported query at our end and we will update the further details within two business days. Until then we appreciate your patience. 

Regards, 
Rahul 



GI Giacomo December 27, 2021 03:24 PM UTC

Hi Rahul,

thank you for your reply, will wait for your answer


Regards,

Giacomo



VN Vignesh Natarajan Syncfusion Team December 30, 2021 06:55 AM UTC

Hi Giacomo,  
 
Thanks for the patience.  
 
Query: “, it will be shown immediatly empty grid with spinning circle that should disappears when grid is populated, is it possible to do this ? 
 
We have analyzed your requirement to display the spinner component while refreshing the browser page and we found that it is not possible to show spinner component while refreshing the browser page. This behavior occur only while refreshing the browser page not while switching between different pages (i.e.) Index - > Counter or FetchData - > Counter.   
 
Because while navigating or refreshing the component, that Page / Component’s Dispose method has to be triggered indicating that component is destroyed before Initializing the component again. But in the case of browser page refresh, Component’s dispose method is not triggered and component is initiated for second time again. So Spinner component is not shown properly in that time delay. This is related to Blazor Framework not to Syncfusion.  
 
Please find the video demonstration for your reference 
 
 
Also refer the below sample for your reference 
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 



GI Giacomo December 30, 2021 02:35 PM UTC

Hi Vignesh,

thx for clarifications!


Regards,

Giacomo



VN Vignesh Natarajan Syncfusion Team December 31, 2021 03:23 AM UTC

Hi Giacomo,  

thanks for the update.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon