Created
June 20, 2017 05:48
-
-
Save filipelinhares/3fdfd808d3f8c7004c7c711e32536d47 to your computer and use it in GitHub Desktop.
Pagination with Javascript
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
function listItems(items, pageActual, limitItems){ | |
let result = []; | |
let totalPage = Math.ceil( items.length / limitItems ); | |
let count = ( pageActual * limitItems ) - limitItems; | |
let delimiter = count + limitItems; | |
if(pageActual <= totalPage){ | |
for(let i=count; i<delimiter; i++){ | |
if(items[i] != null){ | |
result.push(items[i]); | |
} | |
count++; | |
} | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment