svelte-simple-datatables icon indicating copy to clipboard operation
svelte-simple-datatables copied to clipboard

Reset page (pagination) when data is filtered

Open MattPurland opened this issue 4 years ago • 3 comments

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?

MattPurland avatar Dec 09 '20 14:12 MattPurland

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)
}

vincjo avatar Dec 10 '20 09:12 vincjo

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

pa-andrei avatar Aug 27 '21 19:08 pa-andrei

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.

patrick-koenig avatar Oct 10 '22 08:10 patrick-koenig