Here I am fetching some JSON date from a google sheet as you can tell, I addition I would like this data to be sorted on pages containing only three records per page using pagination, with prev/next functions that will update dynamical without the page reloading.
At this moment I am stuck trying to connect the JSON data to the pagination functions to determine the data length and sort the records in multiple pages.
How can I make the JSON data sort it selves in multiple pages, while navigating between the pages using next/prev?
var url = "https://spreadsheets.google.com/feeds/list/1xo6dUfcVOwPA5Lkd8pKevLj6lP-0gOaPXNBZk4jyuGw/od6/public/values?alt\u003djson";
var perPage = 3;
var currentPage = 1;
$.getJSON(url, function(data) {
var output = "";
var length = data.length;
$.each(data.feed.entry, function(index,value) {
output += "Category: " + value.gsx$largeimage.$t + "</br>"+
"Name: " + value.gsx$imagetitle.$t + "</br></br>";
});
$(".test").append(output);
});
function prevPage()
{
if (currentPage > 1) {
currentPage--;
changePage(currentPage);
}
}
function nextPage()
{
if (currentPage < numPages()) {
currentPage++;
changePage(currentPage);
}
}
function changePage(page)
{
// ??
}
function numPages()
{
return Math.ceil(length / perPage);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="test"></div>
<a href="javascript:prevPage()" id="btn_prev">Prev</a>
<a href="javascript:nextPage()" id="btn_next">Next</a>
page: <span id="page"></span>