dynamically destroying elements as they become invisible and recreating them if they become visible again
@tommck Where is your data comming from? If it is some remote source, then the server side is responsible for indexes handling and the front end should not care about this. If you are using ui-scroll datasource.get as a data generator, then negative indexes handling is a part of your datasource logic. Anyway this logic should be implemented somewhere out of ui-scroll directive cause ui-scroll directive is not responsible for data generation and there is no option to tell the ui-scroll that the data will have no negative indexes at all. There may be a lot of ways how to implement it, e.g. https://github.com/angular-ui/ui-scroll/blob/master/demo/chat/chat.js.
Regarding error handling... Still the ui-scroll directive is not responsible for the data generation and the ui-scroll datasource.get is the only place for data retrieving, then I guess datasource.get should be used also for errors handling. And again, there's total freedom: in the example I just mentioned it may looked like Server.request(start, end).then(success).catch(errorHandler)
. So this falls to the ui-scroll user too.
@pavanthakur You don't need any special examples because the ui-scroll was initially designed for the purpose of remote data fetching, just do it in a way
datasource = {
get: function (index, count, success) {
Server.request(index, count).then(function (result) {
success(result.items);
});
}
};
or to be more detailed in terms of javascript-fetch through the GET
datasource = {
get: function (index, count, success) {
fetch('/api/getData?from=' + index + '&to=' + (index + count)).then(function (result) {
success(result.items);
});
}
};
Thank you for reply actually myserver side records have no sequential index and I am trying to bring records according to pagination as below, problem I am facing for the second page of records. Like last 25 record (226 to 250) I am able to load properly with above logic, but next (221 to 225) I am unable to apply logic. I am scrolling last records to first record with scrolling up logic. Basically trying to apply prepend logic.
Sample example as below,
var query = ctx.People.Where(p => p.Name.StartsWith("A"));
var page = query.OrderBy(p => p.Name)
.Select(p => new PersonResult { Name = p.Name })
.Skip(skipRows).Take(pageSize)
.GroupBy(p => new { Total = query.Count() })
.FirstOrDefault();