Server side API? #63
-
Currently my (table) search is using the " I'd also like to handle pagination server side as well, I am fetching it on page load and updating a |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
I haven't designed a server-side API yet because I'm not sure what the best practices are for that. If we want to support server-side sorting / filtering / pagination etc., would it be sufficient to keep the plugin states (i.e. sort keys, filters, page index, etc.) but make the plugins have no effect on the rows? That way, we can use Svelte Headless Table as a way of managing the sort / filter / pagination state, but update the data store for the table independently. |
Beta Was this translation helpful? Give feedback.
-
I saw a |
Beta Was this translation helpful? Give feedback.
-
Hey @Gildedter! @blerrgh actually implemented some server side features at the start of the year but the documentation had to be delayed since the previous framework I was using relied on an old SvelteKit version which was no longer publishable to Vercel. I recently spent a lot of effort migrating the site though, so a documentation update is definitely due. In the meantime, you can refer to this snippet for an idea of how server-side sorting, filtering, and pagination can be implemented: const data = writable([...]);
const table = createTable(data, {
sort: addSortBy({ serverSide: true }),
filter: addTableFilter({ serverSide: true }),
page: addPagination({ serverSide: true }),
});
const columns = table.createColumns(...);
const {rows, pluginStates} = table.createViewModel(columns);
const {sortKeys} = pluginStates.sort;
const {filterValue} = pluginStates.filter;
const {pageSize, pageIndex} = pluginStates.filter;
async function updateQuery() {
const q = new URLSearchParams();
q.set('order_by', $sortKeys[0].id);
q.set('order_dir', $sortKeys[0].order);
q.set('filter', $filterValue);
q.set('limit', String($pageSize));
q.set('skip', String($pageSize * $pageIndex));
$data = await fetch(`/api_endpoint?${q});
}
// ... |
Beta Was this translation helpful? Give feedback.
-
I'm using a different approach to paginate the datable.
And then in the +page.svelte
|
Beta Was this translation helpful? Give feedback.
Hey @Gildedter! @blerrgh actually implemented some server side features at the start of the year but the documentation had to be delayed since the previous framework I was using relied on an old SvelteKit version which was no longer publishable to Vercel.
I recently spent a lot of effort migrating the site though, so a documentation update is definitely due.
In the meantime, you can refer to this snippet for an idea of how server-side sorting, filtering, and pagination can be implemented: