Skip to content

Commit

Permalink
Merge pull request #200 from intuitem/CA-350-Pagination-problem-when-…
Browse files Browse the repository at this point in the history
…switching-form-one-model-table-to-another

Reset the model table page when switching between model tables of different type of objects
  • Loading branch information
eric-intuitem authored Apr 9, 2024
2 parents c1a1706 + f637149 commit 5ab597c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions frontend/src/lib/components/ModelTable/Pagination.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
<script lang="ts">
import type { DataHandler } from '@vincjo/datatables';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import * as m from '$paraglide/messages';
export let handler: DataHandler;
const pageNumber = handler.getPageNumber();
const pageCount = handler.getPageCount();
const pages = handler.getPages({ ellipsis: true });
let urlModel: string | undefined;
let _sessionStorage = null;
onMount(() => {
_sessionStorage = sessionStorage;
});
$: if ($page.url && _sessionStorage) {
const pageData = JSON.parse(_sessionStorage.getItem("model_table_page_data") ?? "{}");
urlModel = (`${$page.url}`).replace("/\/+$/","").split("/").pop()
const currentPage = pageData[urlModel] ?? 1;
handler.setPage(currentPage);
pageData[urlModel] = currentPage;
_sessionStorage.setItem("model_table_page_data",JSON.stringify(pageData));
}
$: if ($pageNumber && urlModel && _sessionStorage) {
const pageData = JSON.parse(_sessionStorage.getItem("model_table_page_data") ?? "{}");
pageData[urlModel] = $pageNumber;
_sessionStorage.setItem("model_table_page_data",JSON.stringify(pageData));
}
</script>

<section class="flex">
Expand Down

0 comments on commit 5ab597c

Please sign in to comment.