Skip to content
This repository has been archived by the owner on Jun 8, 2024. It is now read-only.

Reset page (pagination) when data is filtered #14

Closed
MattPurland opened this issue Dec 9, 2020 · 3 comments
Closed

Reset page (pagination) when data is filtered #14

MattPurland opened this issue Dec 9, 2020 · 3 comments

Comments

@MattPurland
Copy link

I've implemented the ability to filter the underlying data of the table, but if the user navigates to page 2 (for example) then filters the data it stays on page 2 even when there's not enough data for 2 pages.

Is there any way to reset the page? Maybe an exported variable I can change after filtering?

@vincjo
Copy link
Owner

vincjo commented Dec 10, 2020

There is a temporary solution until a more complete and documented API is developed

import { pageNumber } from 'svelte-simple-datatables/src/stores/state.js'

const reset = () => {
    pageNumber.set(1)
}

@pa-andrei
Copy link

Any updates on this issue? The temporary solution is ok but is there an official fix release planned?

@patrick-koenig
Copy link

Since version 0.2.0 and higher, the above approach by @vincjo no longer works.

Now the following workaround can be used to reset the page number:

import { context as contextDatatable } from 'svelte-simple-datatables/src/app/context.js'

const reset = () => {
    contextDatatable.get('svelte-simple-datatable').getPageNumber().update(store => store = 1);
}

The string svelte-simple-datatable works fine if one doesn't use the id={'foobar'} prop. If you use the id-prop, e.g. for multiple instances, simply use the same id in the above workaround code.

@vincjo vincjo closed this as completed Jun 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants