svelte-headless-table icon indicating copy to clipboard operation
svelte-headless-table copied to clipboard

serverItemCount is undefined

Open Gildedter opened this issue 3 months ago • 0 comments

I'm on [email protected] and svelte-headless-table@^0.17.4, with the following code:

// table setup code
const filesTable = createTable(_files, {
    page: addPagination({
        initialPageSize: 15,
        // serverItemCount: writable($_files.length), // still the same error with this uncommented
        serverSide: true
    })
})

const filesTableColumns = filesTable.createColumns([
    filesTable.column({
        header: 'Attachment Type',
        accessor: 'Description'
        // cell: formatNullCell
    }),
    filesTable.column({
        header: 'File 1',
        accessor: 'FileSys1',
        cell: formatNullCell
    }),
    filesTable.column({
        header: 'File 2',
        accessor: 'FileSys2',
        cell: formatNullCell
    }),
    filesTable.column({
        header: 'File 3',
        accessor: 'FileSys3',
        cell: formatNullCell
    }),
    filesTable.column({
        header: 'File 4',
        accessor: 'FileSys4',
        cell: formatNullCell
    }),
    filesTable.column({
        header: 'File 5',
        accessor: 'FileSys5',
        cell: formatNullCell
    })
])

const { headerRows, tableAttrs, tableBodyAttrs, pageRows, pluginStates } =
    filesTable.createViewModel(filesTableColumns)

const {
    pageIndex,
    pageSize,
    pageCount,
    hasPreviousPage,
    hasNextPage,
    serverItemCount
} = pluginStates.page


...etc


// api call
await api
    .url(url.toString())
    .get()
    .error(500, err => serverErrHandler(err))
    .res(async r => {
        if (r.status === 200) {
            const response = await r.json()
            if (response.files.length) {
                $_files = response.files
                console.log(response.totalRows)
                console.log(serverItemCount) <-- also undefined here
                $serverItemCount = response.totalRows
            }
        } else if (r.status === 204) {
            // $_files = []
            notify({
                message: r.statusText,
                level: 'info',
                status: r.status
            })
        }
    })
    .catch(err => {
        console.log(err) <-- getting "store is undefined" error here
        // if (err) {
        //     const { status, messages } = err.json
        //     notify({
        //         message: messages.error,
        //         level: 'danger',
        //         status: status
        //     })
        // }
    })
    .finally(() => {
        disabled = false
    })

Gildedter avatar Apr 01 '24 09:04 Gildedter