Ignore:
Timestamp:
10/07/21 20:37:55 (3 years ago)
Author:
NikolaCenevski <cenevskinikola@…>
Branches:
master
Children:
b8a8d06
Parents:
ee0e297
Message:

Added post grouping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/resources/static/js/pagination.js

    ree0e297 r7888b17  
    55let sort = findGetParameter("sort");
    66let order = findGetParameter("order");
     7let group = findGetParameter("groupBy")
    78
    89let sortByInput = document.getElementById("sortBy");
     
    1213orderInput.value = order;
    1314
     15let groupByInput = document.getElementById("groupBy") === null ? document.createElement("input") : document.getElementById("groupBy");
     16groupByInput.value = group;
     17
    1418sortByInput.addEventListener("change", function () {
    15     window.location.href = url + "?page=" + currentPage + "&sort=" + sortByInput.value + "&order=" + orderInput.value;
     19    window.location.href = url + "?page=" + currentPage + "&sort=" + sortByInput.value + "&order=" + orderInput.value + "&groupBy=" + groupByInput.value;
    1620})
    1721
    1822orderInput.addEventListener("change", function() {
    19     window.location.href = url + "?page=" + currentPage + "&sort=" + sortByInput.value + "&order=" + orderInput.value;
     23    window.location.href = url + "?page=" + currentPage + "&sort=" + sortByInput.value + "&order=" + orderInput.value + "&groupBy=" + groupByInput.value;
     24})
     25
     26groupByInput.addEventListener("change", function () {
     27    window.location.href = url + "?page=" + 1 + "&sort=" + sortByInput.value + "&order=" + orderInput.value + "&groupBy=" + groupByInput.value;
    2028})
    2129
     
    2937
    3038    if (page > 1) {
    31         str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page-1)+'&sort='+sort+'&order='+order+'">Previous</a></li>';
     39        str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page-1)+'&sort='+sort+'&order='+order+'&groupBy='+group+'">Previous</a></li>';
    3240    }
    3341
     
    3543        for (let p = 1; p <= pages; p++) {
    3644            active = page == p ? "active" : "";
    37             str += '<li class="page-item '+active+'"><a class="page-link" href="'+url+'?page='+p+'&sort='+sort+'&order='+order+'">'+ p +'</a></li>';
     45            str += '<li class="page-item '+active+'"><a class="page-link" href="'+url+'?page='+p+'&sort='+sort+'&order='+order+'&groupBy='+group+'">'+ p +'</a></li>';
    3846        }
    3947    }
     
    4149    else {
    4250        if (page > 2) {
    43             str += '<li class="page-item"><a class="page-link" href="'+url+'?page=1&sort='+sort+'&order='+order+'">1</a></li>';
     51            str += '<li class="page-item"><a class="page-link" href="'+url+'?page=1&sort='+sort+'&order='+order+'&groupBy='+group+'">1</a></li>';
    4452            if (page > 3) {
    45                 str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page-2)+'&sort='+sort+'&order='+order+'">...</a></li>';
     53                str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page-2)+'&sort='+sort+'&order='+order+'&groupBy='+group+'">...</a></li>';
    4654            }
    4755        }
     
    6775            }
    6876            active = page == p ? "active" : "";
    69             str += '<li class="page-item '+active+'"><a class="page-link" href="'+url+'?page='+p+'&sort='+sort+'&order='+order+'">'+ p +'</a></li>';
     77            str += '<li class="page-item '+active+'"><a class="page-link" href="'+url+'?page='+p+'&sort='+sort+'&order='+order+'&groupBy='+group+'">'+ p +'</a></li>';
    7078        }
    7179
    7280        if (page < pages-1) {
    7381            if (page < pages-2) {
    74                 str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page+2)+'&sort='+sort+'&order='+order+'">...</a></li>';
     82                str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page+2)+'&sort='+sort+'&order='+order+'&groupBy='+group+'">...</a></li>';
    7583            }
    76             str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+pages+'&sort='+sort+'&order='+order+'">'+pages+'</a></li>';
     84            str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+pages+'&sort='+sort+'&order='+order+'&groupBy='+group+'">'+pages+'</a></li>';
    7785        }
    7886    }
    7987
    8088    if (page < pages) {
    81         str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page+1)+'&sort='+sort+'&order='+order+'">Next</a></li>';
     89        str += '<li class="page-item"><a class="page-link" href="'+url+'?page='+(page+1)+'&sort='+sort+'&order='+order+'&groupBy='+group+'">Next</a></li>';
    8290    }
    8391    str += '</ul>';
Note: See TracChangeset for help on using the changeset viewer.