{"action":"created","issue":{"url":"https://api.github.com/repos/akveo/ng2-smart-table/issues/858","repository_url":"https://api.github.com/repos/akveo/ng2-smart-table","labels_url":"https://api.github.com/repos/akveo/ng2-smart-table/issues/858/labels{/name}","comments_url":"https://api.github.com/repos/akveo/ng2-smart-table/issues/858/comments","events_url":"https://api.github.com/repos/akveo/ng2-smart-table/issues/858/events","html_url":"https://github.com/akveo/ng2-smart-table/issues/858","id":348445133,"node_id":"MDU6SXNzdWUzNDg0NDUxMzM=","number":858,"title":"Pagination starts at page=0","user":{"login":"AbleLincoln","id":12586676,"node_id":"MDQ6VXNlcjEyNTg2Njc2","avatar_url":"https://avatars3.githubusercontent.com/u/12586676?v=4","gravatar_id":"","url":"https://api.github.com/users/AbleLincoln","html_url":"https://github.com/AbleLincoln","followers_url":"https://api.github.com/users/AbleLincoln/followers","following_url":"https://api.github.com/users/AbleLincoln/following{/other_user}","gists_url":"https://api.github.com/users/AbleLincoln/gists{/gist_id}","starred_url":"https://api.github.com/users/AbleLincoln/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AbleLincoln/subscriptions","organizations_url":"https://api.github.com/users/AbleLincoln/orgs","repos_url":"https://api.github.com/users/AbleLincoln/repos","events_url":"https://api.github.com/users/AbleLincoln/events{/privacy}","received_events_url":"https://api.github.com/users/AbleLincoln/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-08-07T18:53:46Z","updated_at":"2018-11-17T13:36:33Z","closed_at":null,"author_association":"NONE","body":"Currently when the ServerDataSource retrieves the first page of data, it GETs the page indexed at 1, like so: `<API endpoint>?_page=1`.\r\n\r\nIs it possible to have pagination start at the zeroth page?"},"comment":{"url":"https://api.github.com/repos/akveo/ng2-smart-table/issues/comments/439617491","html_url":"https://github.com/akveo/ng2-smart-table/issues/858#issuecomment-439617491","issue_url":"https://api.github.com/repos/akveo/ng2-smart-table/issues/858","id":439617491,"node_id":"MDEyOklzc3VlQ29tbWVudDQzOTYxNzQ5MQ==","user":{"login":"AbdullahUsmani","id":10168941,"node_id":"MDQ6VXNlcjEwMTY4OTQx","avatar_url":"https://avatars3.githubusercontent.com/u/10168941?v=4","gravatar_id":"","url":"https://api.github.com/users/AbdullahUsmani","html_url":"https://github.com/AbdullahUsmani","followers_url":"https://api.github.com/users/AbdullahUsmani/followers","following_url":"https://api.github.com/users/AbdullahUsmani/following{/other_user}","gists_url":"https://api.github.com/users/AbdullahUsmani/gists{/gist_id}","starred_url":"https://api.github.com/users/AbdullahUsmani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AbdullahUsmani/subscriptions","organizations_url":"https://api.github.com/users/AbdullahUsmani/orgs","repos_url":"https://api.github.com/users/AbdullahUsmani/repos","events_url":"https://api.github.com/users/AbdullahUsmani/events{/privacy}","received_events_url":"https://api.github.com/users/AbdullahUsmani/received_events","type":"User","site_admin":false},"created_at":"2018-11-17T13:36:33Z","updated_at":"2018-11-17T13:36:33Z","author_association":"NONE","body":"I created a new class: **CustomServerDataSource**, extending the **ServerDataSource** class. \r\n```javascript\r\nexport class CustomServerDataSource extends ServerDataSource \r\n```\r\n\r\nIn this class, I overrode the method **addPagerRequestParams** : \r\n```javascript\r\naddPagerRequestParams(httpParams: HttpParams): HttpParams {\r\n     if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) {\r\n        httpParams = httpParams.set(this.conf.pagerPageKey, this.pagingConf['page'] + (-1));\r\n        httpParams = httpParams.set(this.conf.pagerLimitKey, this.pagingConf['perPage']);\r\n    }\r\n    return httpParams;\r\n}\r\n```\r\n\r\nThe method has only one line different from the original class, done as suggested by @AbleLincoln here:\r\n\r\n\r\n> Here's the quickest (but kind of silly) fix I found:\r\n> \r\n> Change line `112` of [server.data-source.ts](https://github.com/akveo/ng2-smart-table/blob/master/src/ng2-smart-table/lib/data-source/server/server.data-source.ts) to this:\r\n> \r\n> ```ts\r\n> httpParams = httpParams.set(this.conf.pagerPageKey, this.pagingConf['page'] + (-1));\r\n> ```\r\n> \r\n> What I did was add the `+ (-1)` to the `this.pagingConf['page']`. This changes the value of the HTTP parameter for the 'page' parameter. Essentially anytime an HTTP request is made for data (so when the table is first created, or the user changes to a new page), you just subtract 1 from the page number. This basically gives you zero-indexed paging.\r\n> \r\n> > Sidenote: the reason you have to do `+ (-1)` instead of `-1` is some Javascript nonsense. `httpParams.set()` expects a string for the second argument. I guess in Javascript you can add a number to a string and it all works out and can be safely converted to a string. But if you want to _subtract_ a number then the compiler gets fussy and refuses to convert that into a string. IDK man Javascript is wack\r\n> \r\n> Now, this isn't a very robust or smart fix. And we're essentially just hacking the code. What I think needs to be done is that data source should have a config option for where you want your indexing to start. However, this requires changing quite a bit of the code (there are a bunch of hardcoded `1`'s throughout the codebase 😬), so I present this temporary, simpler solution for now. It might be worth submitting a pull request later on down the line\r\n\r\n"}}
{"actor":{"display_login":"AbdullahUsmani"}}