New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

svelte-infinitable

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-infinitable

Svelte Infinitable is a virtual table component that uses native <kbd>table</kbd> elements and supports _infinite scrolling_, _searching_, _filtering_, _sorting_, and more.

  • 0.0.11
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Svelte Infinitable

Svelte Infinitable is a virtual table component that uses native table elements and supports infinite scrolling, searching, filtering, sorting, and more.

Example table

Live demo: https://infinitable.adevien.com/

Sponsor

Aluma

Installation

Svelte Infinitable is built with Svelte 5, which means you need to have Svelte 5 installed in your project.

pnpm add -D svelte-infinitable
# or
yarn add -D svelte-infinitable
# or
npm i -D svelte-infinitable

Usage

[!WARNING] The package is yet to reach version 1.0.0, meaning breaking changes may be introduced with every minor version.

Props

NameTypeDefaultOptionalDescription
itemsTableItem[][]YesThe items to display in the table. If all of the items are loaded ahead of time, set ignoreInfinite to true and call finishInitialLoad() on the table instance when the initial load is completed.
rowHeightnumber-NoThe height of each row in the table.
selectablebooleanfalseYesControls whether the table rows are selectable or not.
overscannumber10YesThe number of rows to render above and below the visible area of the table. Also controls how early the table will call the onInfinite function.
ignoreInfinitebooleanfalseYesControls whether the onInfinite function is called or not. Useful to set to true if you know that you are going to load all the data at once. If set to true, call finishInitialLoad() on the table instance when the initial load is completed.
rowDisabler(item: TableItem, index: number) => booleanundefinedYesA function that takes an item and an index as parameters, and returns a boolean indicating whether the row at that index should be disabled or not.
disabledRowMessagestring'This row cannot be selected'YesThe text that will be displayed when the checkbox of a disabled row is hovered.
classstring''YesClasses to apply to the table wrapper element.
stylestring''YesStyle to apply to the table wrapper element.
debugbooleanfalseYesIf set to true, buttons will be rendered that make it easy to switch between different states of the table.

Events

NameTypeDefaultOptionalDescription
onInfiniteInfiniteHandlerundefinedYesCalled when the table has reached the end of the loaded data.
onFilterFilterHandlerundefinedYesCalled when the filtering of the table changes, and it's in server mode.
onSortSortHandlerundefinedYesCalled when the sorting of the table changes, and it's in server mode.
onSelectSelectHandlerundefinedYesCalled when the selected items change.

Slots

NameArgumentDescription
children (default){ item: TableItem; index: number; selectedCount: number; isAllSelected: boolean }A slot for the table rows.
actions-A slot above the table, but within it's border. It's the recommended place to mount the Search, Refresh, FilterClear, and any other custom components.
headers-A slot for the table headers.
loader-A slot to replace the loading indicator below existing rows.
completed-A slot to replace the message below existing rows, when the table has no more items.
empty-A slot to replace the message when the table has items, but they are filtered out.
loadingEmpty-A slot to replace the message when the table is loading and empty.
completedEmpty-A slot to replace the screen when the table has no more items and empty.
errorEmpty-A slot to replace the screen when the table has an error and empty.
idleEmpty-A slot to replace the screen when the table is idle and empty.
rowsDetail{ rowCount: number; selectedCount: number }A slot to replace the info message below the table.
error{ message: string }A slot to replace the error message below the table.

Example

The following is a barebones example of using Svelte Infinitable. If you want to see a more complex one, check table.svelte in the example direxctory.

<script lang="ts">
	import * as Infinitable from 'svelte-infinitable';
	import type { InfiniteHandler } from 'svelte-infinitable/types';
	import { formatDateString, getTasks, tableHeaders, type TaskData } from '$lib/utils.js';

	let items: TaskData[] = [];
	let page = 1;

	async function loadItems() {
		const limit = 100;
		const { data, depleted } = await getTasks(page++, limit);
		return { data, depleted };
	}

	const onInfinite: InfiniteHandler = async ({ loaded, completed, error }) => {
		try {
			const { data, depleted } = await loadItems();
			depleted ? completed(data) : loaded(data);
		} catch (e) {
			error();
		}
	};
</script>

<Infinitable.Root bind:items rowHeight={36} {onInfinite} class="max-h-[400px]">
	{#snippet headers()}
		{#each tableHeaders as header}
			<Infinitable.Header {header} />
		{/each}
	{/snippet}

	{#snippet children({ index })}
		{@const { id, name, created_at } = items[index] ?? {}}
		<td> {id} </td>
		<td> {name} </td>
		<td> {formatDateString(created_at)} </td>
	{/snippet}
</Infinitable.Root>

FAQs

Package last updated on 28 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc