-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip intermediate requests to datasource if the scrolling was too fast. #120
Comments
I tried to add this logic in my datasource implementation. But looks like ui-scroll makes more than one call for a page (i guess its for the buffer). So its a little harder to put it here. |
I am not sure I understand what problem you are trying to solve Michael Feingold, President On Mon, Oct 3, 2016 at 9:44 PM, subhash-periasamy [email protected]
|
My understanding is that @subhash-periasamy wants to skip intermediate data requesting to prevent expensive rendering of the rows which would be removed after scroll ends. If it is so, I have to say that ui-scroll itself has no such functionality. But you really can improve the behaviour through the datasource extension. We have a useful demo on this, it is called Cache within datasource implementation. Please try it on and investigate sources. I believe this can help. |
Thanks @dhilt . You are right about the problem. I will take a look at the cache implementation. But my rows have fields that changes very frequently and apart from that I will potentially have hundreds of thousands of rows. |
In this case you should not relay on scrolling for doing this. Have a look Michael Feingold, President On Tue, Oct 4, 2016 at 11:25 AM, subhash-periasamy <[email protected]
|
Hi @mfeingold, I don;t understand how reload will help me. Sorry if I am missing anything obvious. Thanks! |
If using cache covers your use case, by all means use it. One thing to as to reload - reload takes a parameter indicating the which row will Michael Feingold, President On Tue, Oct 4, 2016 at 12:01 PM, subhash-periasamy <[email protected]
|
This is a popular topic... look at #31 |
Thanks for digging through the old threads. Currently I am planning to queue the incoming requests in the datasource and execute only last n requests (may be 2 or 3). This would solve my issue. Need to play around a little bit to determine n. I will keep you posted on how it goes. Also I will see if there is a way to get this done within ui-scroll. Thanks for your help! |
I was able to solve this problem by doing the following. Hopefully this helps someone. var last_descriptor = null;
$scope.datasource = {
get: function(descriptor, success) {
var result = $scope.filteredDomains.slice(Math.max(descriptor.index, 0), descriptor.index + descriptor.count);
success(result);
last_descriptor = descriptor;
last_descriptor.position = $window.pageYOffset;
}
};
// When scrolling up a lot, check number of items we are transitioning and "reload" if necessary
$scope.check_for_reload = function() {
if (!last_descriptor) {
return;
}
var new_first_item = -1;
var max_loaded = last_descriptor.index + last_descriptor.count;
if ($window.pageYOffset === 0) {
// reset to zero
new_first_item = 0;
} else {
var position = $window.pageYOffset;
var perc_scrolled = last_descriptor.position / position;
new_first_item = max_loaded * perc_scrolled;
}
// If we are skipping more than "n" items, reload
if (max_loaded - new_first_item > 200) {
$scope.uiScrollAdapter.reload(new_first_item);
}
};
angular.element($window).bind("scroll", $scope.check_for_reload); |
@dustin-s I guess, your solution can be improved by min/max indexes manipulation to keep scroll bar params consistent after reload (https://rawgit.com/angular-ui/ui-scroll/master/demo/userIndexes/userIndexes.html). Do you have a plunker or something like plunker (https://plnkr.co/yNpY0K) for your code? I could such an improvement or even make an official demo... |
I was in the middle if a code freeze at that moment. I'll see if I can work up a plunkr to demo this better. I'm also not sure I want to keep the scroll bars consistent. The issue was that too many were displaying for the browser to render. So I'd rather reset. However I'll try this and see how it plays. Thanks for the suggestion.
|
Seems like a good idea. Unfortunately it might break if the height of the item varies |
I've created a plunkr as you suggested. |
Would debouncing scroll events be useful here? Seems like you should be able to tell which items need to be displayed and you can render them without having to perform the intermediate fetch/render/clip work. |
This is required mainly after I scroll down a few pages. Then drag the scroll thumb all the way to the top. The scroller can skip all the intermediate requests.
I am not sure if I am missing something but I did not find it in the docs.
The text was updated successfully, but these errors were encountered: