Skip to content

A toolkit for creating datatable components with Svelte

License

Notifications You must be signed in to change notification settings

scott3j/datatables

 
 

Repository files navigation

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
  • no dependencies

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'; }>
applySorting( params: {orderBy: Function | string; direction?: 'asc' | 'desc'} = null ): void
filter( value: string, filterBy: Function | string, comparator: Function = null ): void
clearFilters(): 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
select(value: any): void
getSelected(): Writable<any[]>
selectAll(params: { selectBy?: Function | string, scope?: 'all' | 'currentPage' } = { scope: 'all' }): void
isAllSelected(): Readable<boolean>
getTriggerChange(): Writable<number>

About

A toolkit for creating datatable components with Svelte

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 96.2%
  • Svelte 3.2%
  • Other 0.6%