Register scroll event using JSInterop

Hello since there isn't a default scroll event to Grid I am trying to add one using JSInterop but it doesn't work.Here is my code:

protected override async Task OnAfterRenderAsync(bool firstRender){
       if(firstRender){
           await JSRuntime.InvokeVoidAsync("Onscroll");
       }
    }



window.Onscroll = function () {
  var grid = document.getElementsByClassName("e-grid")[0];
 // grid.onscroll = function(){console.log("scrolled")};
  grid.addEventListener("scroll",function(){console.log("scrolled")});
};

Note: If I use the wheel event it works

1 Reply 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team November 2, 2020 08:40 AM UTC

Hi Tom, 

Greetings from Syncfusion support. 

We suggest you to bind the scroll event to Grid’s content div element to achieve this requirement. Please refer and use the below codes in your application. 

 
window.Onscroll = function () { 
    var grid = document.getElementsByClassName("e-gridcontent")[0].firstChild; 
 // grid.onscroll = function(){console.log("scrolled")}; 
  grid.addEventListener("scroll",function(){console.log("scrolled")}); 
}; 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer
Loader.
Up arrow icon