pagination trigger data fetch & load

This commit is contained in:
Corban-Lee Jones 2024-09-26 11:58:44 +01:00
parent 014b30c3ec
commit 4c0928e10c
3 changed files with 19 additions and 9 deletions

View File

@ -1,14 +1,9 @@
# -*- encoding: utf-8 -*-
import logging
import requests
from django.conf import settings
from django.db.models import Subquery
from django.db.utils import IntegrityError
from django_filters import rest_framework as rest_filters
from rest_framework import status, permissions, filters, generics
from rest_framework.response import Response
from rest_framework import permissions, filters, generics
from rest_framework.pagination import PageNumberPagination
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_framework.parsers import MultiPartParser, FormParser

View File

@ -35,6 +35,7 @@ function initializeDataTable(tableId, columns) {
...columns
]
});
bindTablePagination(tableId);
}
@ -100,10 +101,24 @@ async function loadTableData(tableId, url, method) {
// region Pagination
function bindTablePagination(tableId) { // TODO:
function bindTablePagination(tableId) {
let $paginationArea = $("#subTable").closest('.js-tableBody').siblings('.js-tableControls').find('.pagination');
$paginationArea.on("click", ".page-link", function() {
let currentPage = $paginationArea.data("page");
let wantedPage;
if ($(this).hasClass("page-prev")) {
wantedPage = currentPage - 1;
}
else if ($(this).hasClass("page-next")) {
wantedPage = currentPage + 1;
}
else {
wantedPage = $(this).attr("data-page")
}
setTableFilter(tableId, "page", wantedPage);
$(tableId).trigger("doDataLoad");
});
}
@ -114,7 +129,7 @@ function fixTablePagination(tableId) {
setTableFilter(tableId, "page", 1);
}
if (!("page_size" in filters)) {
setTableFilter(tableId, "page_size", 15) // TODO: shouldn't be hard coded
setTableFilter(tableId, "page_size", 1) // TODO: shouldn't be hard coded
}
}

View File

@ -95,7 +95,7 @@ $(document).on("selectedServerChange", async function() {
await loadSubscriptionData();
});
$(document).on("doLoadSubscriptions", async function() {
$(subTableId).on("doDataLoad", async function() {
await loadSubscriptionData();
})