Hide/load syunfucsion spinner

I'm getting data from big database which the first query takes around 10-12 seconds to get my data using grid view - I'm using Blazer with entity.

I would like to display the spinner when I'm loading the data and once all the data get fetched the spinner should be stopped or hided. No mater the location of the spinner.

This is my CSS:

.loader {
    display: none;
    top: 50%;
    left: 50%;
    position: absolute;
    transform: translate(-50%, -50%);
  }
  
  .loading {
    border: 2px solid #ccc;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border-top-color: #1ecd97;
    border-left-color: #1ecd97;
    animation: spin 1s infinite ease-in;
  }
  
  @keyframes spin {
    0% {
      transform: rotate(0deg);
    }
  
    100% {
      transform: rotate(360deg);
    }
  }

this is my js function:

spinner: function(){
        document.getElementsByClassName("loader")[0].style.display = "block";

HTML :

<div class="col-auto offset-5">


        <button class="btn btn-info " @onclick="GetTags" style="width: 175px;">Get Tags</button>
   <div class="loader">
  <div class="loading">
  </div>
</div>
    </div>

and this is my blazor method that gets the data from the database and call the js method 'spinner'

public async Task GetTags()
    {
        await JSRuntime.InvokeVoidAsync("myMap.spinner");
        AllTags = await Task.Run(() => tagsService.Map(InputRadius, SelectedTimeDate, Long, Lat));
        

    }

The current result is when I'm clicking on the GetTags button the button converted to spinner and still loading even if the data fully gathered.

I do believe that I'm doing something wrong but i don't know what it is.

Any hint ?


1 Reply

BS Buvana Sathasivam Syncfusion Team February 23, 2022 06:12 PM UTC

Hi Fadi, 

Greetings from Syncfusion support. 
You can hide the custom div element by setting display to none after data fetching from the database. Please see below the code and sample. 
  
jsinterop.js 
window.myMap = { 
     spinner: function () { 
        document.getElementsByClassName("loader")[0].style.display = "block"; 
    }, 
    spinnerHide: function () { 
        document.getElementsByClassName("loader")[0].style.display = "none"; 
    } 
} 
 

Index.razor 
@code { 
    [Inject] 
    IJSRuntime JsRuntime { get; set; } 
    public async Task GetTags() 
    { 
        await JsRuntime.InvokeVoidAsync("myMap.spinner"); 
        await Task.Delay(2000); 
        await JsRuntime.InvokeVoidAsync("myMap.spinnerHide"); 
    } 
} 
 

We suggest you use our Syncfusion Blazor Spinner component with the Visible property and without interacting with the Javascript file to show or hide the SfSpinner component.  



Please let us know if you have any concerns. 

Regards, 
Buvana S 


Loader.
Up arrow icon