Fix table independent sort + page + totalPages parameter

This commit is contained in:
James Cole committed 2026-10-11 12:31:07 +02:00
1 parent 6232d0f49a
commit b7fb52f168
4 files changed
+36 -29

No files matched your search

@@ -39,8 +39,8 @@ let index = function () {
listPageSize: 50,
objectType: "invalid",
accounts: [],
page: 1, // TODO obsolete, must be per table.
totalPages: 1, // TODO obsolete.
// page: 1, // TODO obsolete, must be per table.
// totalPages: 1, // TODO obsolete.
i18next: null,
anonymous: false,
loadingPage: true,
@@ -100,7 +100,7 @@ let index = function () {
this.sortableTable.sortColumns = this.defaultSortColumns;
this.sortableTable.sortDirections = this.defaultSortDirections;
this.sortableTable.storageKey = this.storageKey;
this.sortableTable.page = this.page;
this.sortableTable.pages = this.defaultPages;
// initialize sortable table.
this.sortableTable.init(this);
@@ -182,7 +182,7 @@ let index = function () {
.list({
active: this.active,
sort: sort,
page: this.page,
page: this.sortableTable.pages["main"],
type: this.objectType,
start: start,
filter: JSON.parse(JSON.stringify(this.filter))["main"],
@@ -195,11 +195,10 @@ let index = function () {
this.debts = {};
this.differences = {};
this.totalPages = parseInt(response.data.meta.pagination.total_pages);
this.sortableTable.totalPages["main"] = parseInt(response.data.meta.pagination.total_pages);
const length = response.data.data.length;
if(this.totalPages <= this.page && 0 === length) {
this.page = this.totalPages;
this.sortableTable.page = this.totalPages;
if(this.sortableTable.totalPages["main"] <= this.sortableTable.pages["main"] && 0 === length) {
this.sortableTable.pages["main"] = this.sortableTable.totalPages["main"];
this.downloadObjects();
}
for (let i = 0; i < response.data.data.length; i++) {
@@ -26,6 +26,7 @@ export class sortableTable {
sortColumns = {};
sortDirections = {};
pages = {};
totalPages= {};
sortColumn = "order"; // todo forbidden to use!
sortDirection = "asc"; // todo forbidden to use!
storageKey = "";
@@ -41,6 +42,8 @@ export class sortableTable {
let tableId = tableIds[i];
this.sortColumns[tableId] = "order";
this.sortDirections[tableId] = "asc";
this.pages[tableId] = 1;
this.totalPages[tableId] = 1;
this.tableIds[tableId] = {
sortColumn: "order",
sortDirection: "asc",
@@ -152,15 +155,15 @@ export class sortableTable {
return false;
}
// old:
this.page = page;
// this.page = page;
// new:
this.pages[tableId] = page;
// should be removed:
this.parent.page = page;
// this.parent.page = page;
// some sort of trigger to parent?
this.parent.updateHistory(page, this.sortColumns, this.sortDirections); // TODO give all pages, sort columns and sort directions to parent
this.parent.updateHistory(this.pages, this.sortColumns, this.sortDirections); // TODO give all pages, sort columns and sort directions to parent
this.parent.downloadObjects();
e.preventDefault();
queueMicrotask(() => {
@@ -385,7 +388,12 @@ function parseQueryParams(search = window.location.search) {
export function initFromQueryParams() {
const params = parseQueryParams();
this.page = parseInt(params.page || "1");
this.defaultPages = params.page || this.defaultPages;
// make sure all defaultPages are integers:
for (let tableId in this.defaultPages) {
this.defaultPages[tableId] = parseInt(this.defaultPages[tableId]);
}
this.defaultSortColumns = params.column ?? this.defaultSortColumns;
this.defaultSortDirections = params.direction ?? this.defaultSortDirections;
}
@@ -395,7 +403,7 @@ export function respondToSortChange(event) {
const tableId = event.detail.tableId;
this.sortableTable.sortColumns[tableId] = event.detail.sortColumn;
this.sortableTable.sortDirections[tableId] = event.detail.sortDirection;
this.updateHistory(this.page, this.sortableTable.sortColumns, this.sortableTable.sortDirections); // TODO Need fix.
this.updateHistory(this.sortableTable.pages, this.sortableTable.sortColumns, this.sortableTable.sortDirections); // TODO Need fix.
this.storeFilterAndSort(this.storageKey, this.sortableTable.sortColumns, this.sortableTable.sortDirections, this.filter); // TODO store for ALL.
this.downloadObjects();
}
+2 -2
View File
@@ -17,7 +17,7 @@
:route="route('accounts.create', $objectType) . '?_from=' . urlencode($FF3_FROM)"
:linkTitle="__('firefly.make_new_'. $objectType . '_account')"/>
<div class="card-body p-0">
<template x-if="totalPages > 1">
<template x-if="sortableTable.totalPages.main > 1">
<x-elements.alpine.page-navigation sort-identifier="main"/>
</template>
@@ -367,7 +367,7 @@
</template>
</table>
<template x-if="totalPages > 1">
<template x-if="sortableTable.totalPages.main > 1">
<x-elements.alpine.page-navigation sort-identifier="main"/>
</template>
</div>
@@ -1,31 +1,31 @@
<template x-if="totalPages > 1" x-effect="sortableTable ? sortableTable.capturePageNavigation() : null">
<template x-if="sortableTable.totalPages.{{ $sortIdentifier }} > 1" x-effect="sortableTable ? sortableTable.capturePageNavigation() : null">
<div class="m-2">
<nav data-sort-identifier="{{ $sortIdentifier }}">
<ul class="pagination">
<li :class="{'page-item': true, 'disabled': 1 === page}" :aria-disabled="1 === page ? 'true' : 'false'" aria-label="{!! __('pagination.previous') !!}">
<template x-if="1 === page">
<li :class="{'page-item': true, 'disabled': 1 === sortableTable.pages.{{ $sortIdentifier }} }" :aria-disabled="1 === sortableTable.pages.{{ $sortIdentifier }} ? 'true' : 'false'" aria-label="{!! __('pagination.previous') !!}">
<template x-if="1 === sortableTable.pages.{{ $sortIdentifier }}">
<span class="page-link" aria-hidden="true">‹</span>
</template>
<template x-if="page > 1">
<a class="page-link" :data-page="(page-1)" :href="pageNavUrl + '?page=' + (page - 1)" rel="prev" aria-label="{!! __('pagination.previous') !!}" title="{!! __('pagination.previous') !!}">‹</a>
<template x-if="sortableTable.pages.{{ $sortIdentifier }} > 1">
<a class="page-link" :data-page="(sortableTable.pages.{{ $sortIdentifier }}-1)" :href="pageNavUrl + '?page[{{ $sortIdentifier }}]=' + (sortableTable.pages.{{ $sortIdentifier }} - 1)" rel="prev" aria-label="{!! __('pagination.previous') !!}" title="{!! __('pagination.previous') !!}">‹</a>
</template>
</li>
<template x-for="current in totalPages" :key="current">
<li class="page-item" :class="{'page-item': true, 'active': current === page}">
<template x-if="current !== page">
<a class="page-link" :data-page="current" :href="pageNavUrl+'?page=' + current" x-text="current" :aria-label="current"></a>
<template x-for="current in sortableTable.totalPages.{{ $sortIdentifier }}" :key="current">
<li class="page-item" :class="{'page-item': true, 'active': current === sortableTable.pages.{{ $sortIdentifier }}}">
<template x-if="current !== sortableTable.pages.{{ $sortIdentifier }}">
<a class="page-link" :data-page="current" :href="pageNavUrl+'?page[{{ $sortIdentifier }}]=' + current" x-text="current" :aria-label="current"></a>
</template>
<template x-if="current === page">
<template x-if="current === sortableTable.pages.{{ $sortIdentifier }}">
<span class="page-link" x-text="current"></span>
</template>
</li>
</template>
<li class="{'page-item': true, 'disabled': totalPages === page" :aria-disabled="totalPages === page ? 'true' : 'false'" aria-label="{!! __('pagination.next') !!}">
<template x-if="totalPages > page">
<a class="page-link" :data-page="(page+1)" :href="pageNavUrl+'?page=' + (page +1)" rel="next" aria-label="{!! __('pagination.next') !!}" title="{!! __('pagination.next') !!}">
<li class="{'page-item': true, 'disabled': sortableTable.totalPages.{{ $sortIdentifier }} === sortableTable.pages.{{ $sortIdentifier }}" :aria-disabled="sortableTable.totalPages.{{ $sortIdentifier }} === sortableTable.pages.{{ $sortIdentifier }} ? 'true' : 'false'" aria-label="{!! __('pagination.next') !!}">
<template x-if="sortableTable.totalPages.{{ $sortIdentifier }} > sortableTable.pages.{{ $sortIdentifier }}">
<a class="page-link" :data-page="(sortableTable.pages.{{ $sortIdentifier }}+1)" :href="pageNavUrl+'?page[{{ $sortIdentifier }}]=' + (sortableTable.pages.{{ $sortIdentifier }} +1)" rel="next" aria-label="{!! __('pagination.next') !!}" title="{!! __('pagination.next') !!}">
›</a>
</template>
<template x-if="totalPages === page">
<template x-if="sortableTable.totalPages.{{ $sortIdentifier }} === sortableTable.pages.{{ $sortIdentifier }}">
<span class="page-link" aria-hidden="true">›</span>
</template>
</li>