{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/ui-scroll/issues/58","repository_url":"https://api.github.com/repos/angular-ui/ui-scroll","labels_url":"https://api.github.com/repos/angular-ui/ui-scroll/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/ui-scroll/issues/58/comments","events_url":"https://api.github.com/repos/angular-ui/ui-scroll/issues/58/events","html_url":"https://github.com/angular-ui/ui-scroll/issues/58","id":139011792,"number":58,"title":"Working with page #/page size vs index/offset","user":{"login":"hornetnz","id":1258688,"avatar_url":"https://avatars.githubusercontent.com/u/1258688?v=3","gravatar_id":"","url":"https://api.github.com/users/hornetnz","html_url":"https://github.com/hornetnz","followers_url":"https://api.github.com/users/hornetnz/followers","following_url":"https://api.github.com/users/hornetnz/following{/other_user}","gists_url":"https://api.github.com/users/hornetnz/gists{/gist_id}","starred_url":"https://api.github.com/users/hornetnz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hornetnz/subscriptions","organizations_url":"https://api.github.com/users/hornetnz/orgs","repos_url":"https://api.github.com/users/hornetnz/repos","events_url":"https://api.github.com/users/hornetnz/events{/privacy}","received_events_url":"https://api.github.com/users/hornetnz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-07T15:47:45Z","updated_at":"2016-03-07T18:18:19Z","closed_at":null,"body":"I'm wondering if anyone has been able to make this module work using page #/page size API calls? The API i'm plugging into requires these instead of index & offset. Calls when scrolling down are obvious & easy, but because of the way the buffer clears itself, I haven't found a way to make it work when scrolling up. Could the buffer functionality be changed to remove whole chunks instead of half?"},"comment":{"url":"https://api.github.com/repos/angular-ui/ui-scroll/issues/comments/193378381","html_url":"https://github.com/angular-ui/ui-scroll/issues/58#issuecomment-193378381","issue_url":"https://api.github.com/repos/angular-ui/ui-scroll/issues/58","id":193378381,"user":{"login":"ribeirobreno","id":1036515,"avatar_url":"https://avatars.githubusercontent.com/u/1036515?v=3","gravatar_id":"","url":"https://api.github.com/users/ribeirobreno","html_url":"https://github.com/ribeirobreno","followers_url":"https://api.github.com/users/ribeirobreno/followers","following_url":"https://api.github.com/users/ribeirobreno/following{/other_user}","gists_url":"https://api.github.com/users/ribeirobreno/gists{/gist_id}","starred_url":"https://api.github.com/users/ribeirobreno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ribeirobreno/subscriptions","organizations_url":"https://api.github.com/users/ribeirobreno/orgs","repos_url":"https://api.github.com/users/ribeirobreno/repos","events_url":"https://api.github.com/users/ribeirobreno/events{/privacy}","received_events_url":"https://api.github.com/users/ribeirobreno/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T18:18:19Z","updated_at":"2016-03-07T18:18:19Z","body":"My take on this was:\r\n - which items are actually being requested?\r\n    - `--index; // if using zero based records`\r\n    - `endItem = index + count;`\r\n    - `startItem = (index<0?0:index); // if it doesn't have negative items, otherwise just use index`\r\n - retrieve pages (often, more than one) based on what index, count and page size i'm working.\r\n    - `pageStart = Math.floor(startItem/pageSize)`\r\n    - `pageEnd = Math.ceil(endItem/pageSize)`\r\n    - check if pageEnd >= totalPages, if totalPages is available\r\n - join all the arrays for each page\r\n - [slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice#Return_a_portion_of_an_existing_array)  the resulting array to get the desired range.\r\n    - `diff = pageStart * pageSize`\r\n    - `data.slice(startItem - diff, endItem - diff)`\r\n\r\nBe aware that ui-scroll's index is one based while the arrays are zero based. In my case it was just the case to decrement the index before anything as my pages are also zero based. #44 "}}