Forked from odykyi/lodash-js-pagination-page-skip-sort-order-limit.js
Created
October 20, 2018 18:42
-
-
Save eznix86/7867129a1bf87bfb08adef95af89ce65 to your computer and use it in GitHub Desktop.
lodash-js-pagination-page-skip-sort-order-limit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* PAGINATION WITH SORTING AND PAGING */ | |
| const page = 1; // input page, min value 1 | |
| const limit = 2; // input limit min value 1 | |
| /* INPUT ARRAY */ | |
| const array = [ | |
| { Editable: true, Name: "Daniel Test", Site: "SE100"}, | |
| { Editable: true, Name: "Test new", Site: "SE100"}, | |
| { Editable: false, Name: "Test", Site: "SE100"}, | |
| ]; | |
| /* PAGINATION WITH SORTING AND PAGING */ | |
| const result = _(array) | |
| .orderBy(['Name'], ['asc']) // sort by ascendind | |
| .drop((page - 1) * limit) // page in drop function starts from 0 | |
| .take(limit) // limit 2 | |
| .value(); | |
| console.log(result); | |
| console.log(JSON.stringify(result)); | |
| /* | |
| RESULT: | |
| limit 2 | |
| sort by ascendind | |
| [ | |
| { | |
| "Editable":true, | |
| "Name":"Daniel Test", // name sorted by ascendind | |
| "Site":"SE100" | |
| }, | |
| { | |
| "Editable":false, | |
| "Name":"Test", | |
| "Site":"SE100" | |
| } | |
| ] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment