Open robots4life opened 1 month ago
https://github.com/robots4life/shadcn-svelte-data-table/blob/main/src/routes/data-table.svelte#L85-L87
// pageCount and pageSize must be included even though they are not used
// only if pageCount and pageSize are included will sort work correctly
const { hasNextPage, hasPreviousPage, pageIndex, pageCount, pageSize } = pluginStates.page;
https://shadcn-svelte.com/docs/components/data-table#enable-the-addpagination-plugin
Ideally when introducing pagination to the Date Table in the docs this could be pointed out.
In the next step we are going to add sorting to the data table, for pagination and sorting to work correctly you will have to modify
pluginStates.page
, more about this in the next step.
const { hasNextPage, hasPreviousPage, pageIndex, pageCount, pageSize } = pluginStates.page;
https://shadcn-svelte.com/docs/components/data-table#make-header-cell-sortable
If you like to use sorting with an icon on condition of the sort order and you have pagination in place you will need to add
pageCount
andpageSize
topluginStates.page
.
{#if props.sort.order === 'asc'}
<ArrowUp class={'ml-2 h-4 w-4'} />
{:else}
<ArrowDown class={'ml-2 h-4 w-4'} />
{/if}
Describe the bug
In a simple Data Table, when having pagination and sort enabled the the
props
object is missing thesort
property, hence a condition to check for thesort
property with the aim to showArrowUp
orArrowDowm
icons does not work.Not using Shadcn-Svelte does not have the issue as can been see in this REPL. https://svelte.dev/repl/9b98604e674b482fa50ed1b8ab5fd1e2?version=4.2.18
Reproduction
https://github.com/robots4life/shadcn-svelte-data-table/tree/main
Logs
No response
System Info
Severity
annoyance