How to preserve current page when calling setRows #165
-
Maybe I have a weird use case, but I'm initializing a table using I've noticed that when the data updates, the current page resets to page one. This behavior is problematic for my application since the data changes frequently and retaining the current page is essential. Is there a way to preserve the currently selected page even when data changes? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I guess it is possible inside your data fetching function. const page = table.currentPage
table.setRows(data)
table.setPage(page) Let me know if this induces a visible and annoying page break in your UI |
Beta Was this translation helpful? Give feedback.
-
Thx 👍 // List.svelte
<script lang="ts">
let { data } = $props()
const table = new TableHandler(data)
const update = () => {
const page = table.currentPage
table.setRows(data)
table.setPage(page)
}
$effect(() => {
data // detects changes in data prop
update()
})
</script> |
Beta Was this translation helpful? Give feedback.
Thx 👍
We have similar patterns too.
If I remember correctly, inside $effect in List.svelte, when data changes, you can use a function instead of instructions, it should work. Not sure 100% though