/datatables

A toolkit for creating datatable components with Svelte

Primary LanguageTypeScriptMIT LicenseMIT

logo

svelte simple datatables

A toolkit for creating datatable components with Svelte

npm version last commit

Presentation

This package provides an API to handle data and related events : rows, filters, pagination, search, sort...

  • Headless by design
  • Typescript support
  • SSR compatibility

Also provides some sample components, which you can grab and customize in your own project.


🌐 Live examples


Install

npm i -D @vincjo/datatables

Sample code

<script lang="ts">
    import { DataHandler } from '@vincjo/datatables'
    import { someData } from './data'

    const handler = new DataHandler(someData, { rowsPerPage: 50 })
    const rows = handler.getRows()
</script>

<table>
    <thead>
        <tr>
            <th>First name</th>
            <th>Last name</th>
        </tr>
    </thead>
    <tbody>
        {#each $rows as row}
            <tr>
                <td>{row.first_name}</td>
                <td>{row.last_name}</td>
            </tr>
        {/each}
    </tbody>
</table>

DataHandler methods

getRows(): Readable<any[]>
setRows( data: any[] ): void
sort( orderBy: Function | string ): void
sortAsc( orderBy: Function | string ): void
sortDesc( orderBy: Function | string ): void
getSorted(): Writable<{ identifier?: string; direction?: 'asc' | 'desc'; }>
filter( value: string, filterBy: Function | string ): void
search( value: string, scope?: string[] ): void
clearSearch(): void
getRowsPerPage(): Writable<number | null>
getRowCount(): Readable<{ total: number; start: number; end: number; }>
getPages( param: { ellipsis: boolean } ): Readable<number[]>
getPageCount(): Readable<number>
getPageNumber(): Readable<number>
setPage( value: number | ‘previous’ | ‘next’ ): void
getTriggerChange(): Writable<number>