Created
September 26, 2017 08:59
-
-
Save odykyi/7c6ef7b58eecb08c7b748f1d3ee31343 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.6/lodash.min.js"></script>