Spinner


Hello! When I try use manual spinner I got error. Please help !!! Very need

@ViewChild(GridComponent) public gridInit: GridComponent;
public ngAfterViewInit() {
this.grid = this.gridInit;
if (this.loadingReports) {
this.grid.showSpinner();
}
}



7 Replies

VA Venkatesh Ayothi Raman Syncfusion Team June 22, 2018 12:47 PM UTC

Hi Ali, 

 
Thanks for using Syncfusion products.  
 
As from your query, we suspect that do you want dynamically to show or hide spinner in Grid. We went through your code example which you have shared for us and found that you are tried to load the spinner before the Grid element appends to the DOM. This is the cause of this issue, so we suggest you use load event or create an event to show or hide spinner. Please refer to the following code example, 
 
 
<button (click)='show($event)'>showSpinner</button> 
    <button (click)='hide($event)'>hideSpinner</button> 
    <ejs-grid #grid [dataSource]='data' > 
                <e-columns> 
. . 
                </e-columns> 
                </ejs-grid> 

show(args:any){ 
      
           this.Grid.showSpinner(); 
       
   
     
     hide(args:any){ 
      
       this.Grid.hideSpinner(); 
   
   


In that above code example, we have shown/hide the spinner by using button click for your reference. We have also prepared a sample for your convenience which can be referred from following link, 

Please let us know if you have any further assistance on this. 


Regards, 
Venkatesh Ayothiraman. 



AK Ali Kholmatov June 22, 2018 12:53 PM UTC

thanks, but what about dynamic data( above my code used loading...) ? and Can I off spinner for grid and use manual? 


VA Venkatesh Ayothi Raman Syncfusion Team June 27, 2018 03:46 AM UTC

Hi Ali Kholmatov, 
 
We have checked your query and you can achieve your requirement by using 'click()' event which is used to bind data dynamically in grid. We have prepared a simple sample based on your query in which we can use custom templates on the spinner instead of the default spinner by specifying the setSpinner method. we can show and hide spinner by using showSpinner() and hideSpinner()methods. Hence, you can show and hide the spinner manually. Please refer to the below example code, Documentation link and sample link. 
 
[component.ts] 
import { setSpinner } from '@syncfusion/ej2-popups'; 
 
setSpinner({ template: '<div style="width:100%;height:100%" class="custom-rolling"><div></div></div>'}); 
 
@Component({ 
  selector: 'app-root', 
  template: `<button ej-button class='e-flat' (click)='click()'>Click</button> 
  <button (click)='show()'>show spinner</button> 
  <button (click)='hide()'>hide spinner</button> 
<ejs-grid [dataSource]='data' id="gridcomp"  allowPaging='true'> 
<e-columns> 
    <e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right'></e-column> 
    <e-column field='CustomerName' headerText='Customer Name' [showInColumnChooser]='false'></e-column> 
       . . . .  
</ejs-grid>`, 
  styleUrls: ['./app.component.css'], 
  encapsulation: ViewEncapsulation.Emulated 
}) 
export class AppComponent implements OnInit { 
  public data: Object[]; 
  
  @ViewChild(GridComponent) public gridInit: GridComponent; 
 ngOnInit(): void { 
      
  } 
  show(args:any){ 
  this.gridInit.showSpinner(); 
  } 
  click(): void { 
  this.gridInit.dataSource = orderData; 
   } 
  hide(args:any){ 
   this.gridInit.hideSpinner(); 
  } 
 
} 
 
 
                                 
 
 
 
Regards, 
Gurupriyadharshini S. 



AK Ali Kholmatov June 27, 2018 06:42 AM UTC

Thanks , but how Can I get this ?


@ViewChild(GridComponent) public gridInit: GridComponent;
public ngAfterViewInit() {
this.grid = this.gridInit;
if (this.loadingReports) {
this.grid.showSpinner();
}
}


VA Venkatesh Ayothi Raman Syncfusion Team June 28, 2018 01:13 PM UTC

Hi Ali, 


Thanks for using Syncfusion products.  
 
As from your query, we suspect that would you like to hide the default spinner and load your own customized spinner before the grid rendering. If so, we have achieved your requirement using grid load event like as follows,  
[Grid]  
<div id='customSpinner'></div> 
<ejs-grid #grid [dataSource]='data' (load)='load($event)'> 
                <e-columns> 
. .   . 
                </e-columns> 
                </ejs-grid>  
 
 
ngOnInit(): void { 
         
         
        //here we can show the custom spinner before the grid append to dom element 
         let spinnerTarget: HTMLElement = document.querySelector('#customSpinner') as HTMLElement; 
                createSpinner({ target: spinnerTarget , width: '20px' }); 
                showSpinner(spinnerTarget); 
 
    } 
     
[Load event]  
<script>  
  
    load(args:any){ 
      
      //here we can hide the default waiting popup spinner for Grid  
       
       this.Grid.element.querySelector('.e-spinner-pane').style.display = "none";   
       
 
    }  
</script>  
  
Note: In above code example, we have shown the custom spinner in ngonInit method. 
 
 
 
Regards, 
Venkatesh Ayothiraman. 



GO Goutham June 5, 2019 01:36 PM UTC

Hi,
      I am fetching the data using api service on initial rendering of page(api call in ngAfterViewInit) and attached data to grid data source,data is rendering correctly with out use of spinner.but when i used the showSpinner()(to use default grid spinner provided by sync fusion) method in it to initilize the spinner,showing below error. 
     As you mentioned above that "you are trying to load the spinner before the Grid element appends to the DOM".But i am showing spinner after view init lifecycle hook(Respond after Angular initializes the component's views and child views / the view that a directive is in)






PS Pavithra Subramaniyam Syncfusion Team June 11, 2019 03:32 AM UTC

Hi Gautham, 

Thanks for contacting Syncfusion support. 

We have analyzed your query. We would like to inform you that, the Grid’s element will not be rendered in the “ngAfterViewInit”, this is why the script error occurred. To overcome this problem, we would like to suggest you to use the “ngAfterContentChecked” instead of “ngAfterViewInit”. In this method, the Grid’s element will be rendered and so you can use the “showSpinner” 


    ngAfterContentChecked(){  
        this.Grid.showSpinner();  
    } 


Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


Loader.
Up arrow icon