svelte-simple-datatables
svelte-simple-datatables copied to clipboard
Reset page (pagination) when data is filtered
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?
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)
}
Any updates on this issue? The temporary solution is ok but is there an official fix release planned?
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.