Closed Shavinder closed 3 weeks ago
Hi,
Do you trigger reload in your Pagination
and Search
components using handler.invalidate()
?
Example for pagination:
const setPage = (value: 'previous' | 'next' | number) => {
handler.setPage(value)
handler.invalidate()
}
Hello, Thanks for the quick reply! Much appreciated. Yes I have this in my Paginator component:
<script>
export let handler;
const pageNumber = handler.getPageNumber();
const pageCount = handler.getPageCount();
const pages = handler.getPages({ ellipsis: true });
const setPage = (value) => {
handler.setPage(value);
handler.invalidate();
};
</script>
<!-- Desktop buttons -->
<section class="btn-group variant-ghost-surface [&>*+*]:border-surface-500 h-10 hidden lg:block">
<button
type="button"
class="hover:variant-soft-secondary"
class:disabled={$pageNumber === 1}
on:click={() => setPage('previous')}
>
←
</button>
{#each $pages as page}
<button
type="button"
class="hover:variant-soft-secondary"
class:active={$pageNumber === page}
class:ellipse={page === null}
on:click={() => setPage(page)}
>
{page ?? '...'}
</button>
{/each}
<button
type="button"
class="hover:variant-soft-secondary"
class:disabled={$pageNumber === $pageCount}
on:click={() => setPage('next')}
>
→
</button>
</section>
<!-- Mobile buttons -->
<section class="lg:hidden">
<button
type="button"
class="btn variant-ghost-surface mr-2 mb-2 hover:variant-soft-secondary"
class:disabled={$pageNumber === 1}
on:click={() => setPage('previous')}
>
←
</button>
<button
type="button"
class="btn variant-ghost-surface mb-2 hover:variant-soft-secondary"
class:disabled={$pageNumber === $pageCount}
on:click={() => setPage('next')}
>
→
</button>
</section>
Ok fine
For what I saw in the code, your load function just need to return rows as you probably try initially and commented:
const reload = async (state) => {
const response = await fetch(`/api/services${getParams(state)}`);
const json = await response.json();
state.setTotalRows(json.count);
console.log(json.items);
- handler.setRows(json.items);
+ return json.items;
}
invalidate()
executes this load function and updates rows according to what it returns (your server data)
Otherwise I really don't see what is missing
I don't know what happened. Maybe it's because I restarted the dev server, but it's working now! I swear I have been at this for at least 3 hours and now return json.items;
is having the desired effect. Thanks! Your prompt help is much appreciated.
Hi, I am using this code in my +page.svelte:
You'll see that I am manually setting the rows on the handler in the reload function. If I don't, even though the state changes via the UI and the data is fetched correctly, the table rows do not change. Any idea what am I doing wrong?