angular-ui / ui-scroll

Unlimited bidirectional scrolling over a limited element buffer for AngularJS applications
http://angular-ui.github.io/ui-scroll/demo/
MIT License
327 stars 107 forks source link

How can I prevent datasource.get when scroll up? #153

Closed Lezeper closed 7 years ago

Lezeper commented 7 years ago

How can I prevent datasource.get event be triggered when scroll up? I just want to load more data when scroll down..,

Thanks, Lewis

dhilt commented 7 years ago

@Lezeper This behaviour could be provided via datasource.get code. Let's assume that the start data index is 0. Then we should restrict the result as follows:

var min = 0;
datasource.get = function (index, count, success) {
  var result = [];
  var start = Math.max(min, index);
  var end = index + count - 1;
  if (start <= end) {
    for (var i = start; i <= end; i++) {
      result.push("item #" + i);
    }
  }
  success(result);
};

But if we are talking about remote data retrieving, something like

datasource.get = function (index, count, success) {
  Server.request(index, count).then(function (result) {
    success(result.items);
  });
}

, then I would suggest to do it on Server side. If index < 0 then result.items length should be less then count (up to the empty array []).

The empty result will prevent scroll processing.

Lezeper commented 7 years ago

Issue solved.