We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to achieve virtual scrolling for contents using the ejScroller?

How to achieve virtual scrolling for contents using the ejScroller?

What is Virtual Scrolling?

The virtual scrolling is used to display the large amounts of records without paging. When scrolling with the vertical scrollbar, AJAX requests will be executed to load and refresh the existing records.

How to achieve this virtual scrolling?

We can achieve this virtual scrolling in ejScroller using our existing event “scroll” and method “refresh” of ejScroller.

“Scroll” event will be trigger at that time of scrolling and the refresh method used to refresh the vertical scrollbar handle based on height of the target area content.

When the scroll bar handle reaches its end points we can upload the data using AJAX request in scroll event. Also we need to call refresh methods to refresh the scroll bar based on current content (after new content loaded success fully).

Please refer the below code snippet

contentLoaded = false;

$("#scrollcontent").ejScroller({

scroll: function (e) {

if (obj) {

scrollerpositon=e.scrollTop;

if (!contentLoaded && (document.getElementsByClassName("sampleContent")[0].scrollHeight-e.scrollTop) <= obj.option("height")) {

$.ajax({

url: "../Content/samplecontent/mvccontent.html", success: function (result) {

newitem = $("

").addClass("newitem");

newitem.text(result);

newitem.appendTo(".sampleContent");

contentLoaded = true;

obj.refresh();

obj.option("scrollTop", scroll);

 

}

});

}

}

}

});
obj = $("#scrollcontent").data("ejScroller");


In this code, document.getElementsByClassName("sampleContent")[0].scrollHeight-e.scrollTop > obj.option(“height”) is used to find whether the vertical scroll bar handle reaches is end points in scroll bar. When the handle is reaches its end points, we have loaded the data and then appends this to target pane of scroll bar.

Like this whenever the scroll bar’s vertical handle reaches its end points another new content will be loaded and this process will be continued until all the contents will get loaded successfully.

Sample: Virtual scrolling using scroller

Article ID: Published Date: Last Revised Date: Platform: Control:
5093 06/01/2015 06/01/2015 JavaScript ejScroller
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon