
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
svelte-datatables-net
Advanced tools
svelte-datatables-net is a svelte/sveltekit component that turns data into an interactive HTML table. Inspired by datatables.net.
svelte-datatables-net is a svelte/sveltekit component that turns data into an interactive HTML table. Inspired by datatables.net.
npm install svelte-datatables-net
functionCreateDatatable
: A function to create an object with all the states of the component.Engine
: This is a hidden component (it won't display anything on the screen). However, it is critical for the other components to work together. You must always use it!Search
: A svelte component with a search input.RowsPerPage
: A svelte component with a select input to choose the number of rows per page.Pagination
: A svelte component to change the active page.Sort
: A svelte component that enable sorting for a specific column.typeDatatable
: If you are using typescript, it is a type definition for the component states.functionCreateDatatable
:PARAMETER | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
---|---|---|---|---|
parData | AN ARRAY WITH THE DATA. | Generic[] | YES | - |
parSearchableColumns | AN ARRAY WITH THE SEARCHABLE COLUMNS (KEYS OF parData ). | (keyof Generic)[] | NO | undefined |
parSearchString | THE SEARCH STRING CAN BE SET PREVIOUSLY WITH THIS PROP. | string | NO | '' (EMPTY STRING) |
parRowsPerPage | THE INITIAL NUMBER OF ROWS PER PAGE. | string (NUMERIC STRING OR 'all' ) | NO | 'all' |
parSortBy | THE INITIAL SORT COLUMN (A KEY OF parData ). | keyof Generic | NO | undefined (NO INITIAL SORTING) |
parSortOrder | THE INITIAL SORT ORDER | 'ascending' OR 'descending' | NO | 'ascending' |
parSortFunction | A COMPARE FUNCTION THAT SPECIFIES THE INITIAL SORT ORDER. (MORE DETAILS HERE) | (a: Generic, b: Generic) => number | NO | A STANDARD FUNCTION TO SORT ALPHABETICALLY. |
Engine
:PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
---|---|---|---|---|
propDatatable | AN OBJECT WITH THE DATATABLE STATES (OBJECT CREATED WITH functionCreateDatatable ) | typeDatatable<Generic> | YES | - |
Search
:PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
---|---|---|---|---|
propDatatable | AN OBJECT WITH THE DATATABLE STATES (OBJECT CREATED WITH functionCreateDatatable ) | typeDatatable<Generic> | YES | - |
propPlaceholder | SEARCH INPUT PLACEHOLDER. | string | NO | 'Type here...' |
RowsPerPage
:PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
---|---|---|---|---|
propDatatable | AN OBJECT WITH THE DATATABLE STATES (OBJECT CREATED WITH functionCreateDatatable ) | typeDatatable<Generic> | YES | - |
Pagination
:PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
---|---|---|---|---|
propDatatable | AN OBJECT WITH THE DATATABLE STATES (OBJECT CREATED WITH functionCreateDatatable ) | typeDatatable<Generic> | YES | - |
OTHER PROPS... | SEE THIS. | - | NO | - |
Sort
:PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT |
---|---|---|---|---|
propDatatable | AN OBJECT WITH THE DATATABLE STATES (OBJECT CREATED WITH functionCreateDatatable ) | typeDatatable<Generic> | YES | - |
propIconSize | SIZE OF THE SORT ICON | number | NO | 10 |
<script>
import { Engine, functionCreateDatatable, Pagination, RowsPerPage, Search, Sort } from 'svelte-datatables-net';
const arrayUsers = [
{ id: 9, name: 'Denzel', age: 24, city: 'Newcastle' },
{ id: 12, name: 'Olga', age: 35, city: 'Las Cruces' },
{ id: 13, name: 'Barry', age: 27, city: 'Newport' },
{ id: 10, name: 'Anthony', age: 47, city: 'Los Banos' },
{ id: 2, name: 'Mary', age: 45, city: 'Los Angeles' },
{ id: 1, name: 'John', age: 21, city: 'New York' },
{ id: 3, name: 'Mark', age: 23, city: 'Boston' },
{ id: 5, name: 'Brian', age: 22, city: 'New Orleans' },
{ id: 14, name: 'Larry', age: 41, city: 'Los Altos' },
{ id: 4, name: 'Cris', age: 32, city: 'Las Vegas' },
{ id: 6, name: 'Stuart', age: 46, city: 'Los Gatos' },
{ id: 7, name: 'Owen', age: 24, city: 'Boston' },
{ id: 8, name: 'Paul', age: 33, city: 'Las Vegas' },
{ id: 11, name: 'Fred', age: 25, city: 'Boston' },
{ id: 15, name: 'Richard', age: 29, city: 'Boston' },
{ id: 16, name: 'Bruna', age: 31, city: 'Las Vegas' }
];
let objectDatatable = functionCreateDatatable({
parData: arrayUsers,
parSearchableColumns: ['name', 'city'],
parRowsPerPage: '5',
parSearchString: '',
parSortBy: 'city',
parSortOrder: 'ascending'
});
</script>
<Engine bind:propDatatable={objectDatatable} />
<p>
<span>Search:</span>
<Search bind:propDatatable={objectDatatable} propPlaceholder="Type here..." />
</p>
<p>
<RowsPerPage bind:propDatatable={objectDatatable}>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="all">ALL</option>
</RowsPerPage>
<span>RESULTS PER PAGE</span>
</p>
<p>
<Pagination bind:propDatatable={objectDatatable} propSize="small" />
</p>
<table>
<thead>
<tr>
<th><Sort bind:propDatatable={objectDatatable} propColumn={'id'}>ID (click here)</Sort></th>
<th><Sort bind:propDatatable={objectDatatable} propColumn={'name'}>NAME (click here)</Sort>
</th>
<th>AGE</th>
<th>CITY</th>
</tr>
</thead>
<tbody>
{#each objectDatatable.arrayData as row}
<tr>
<td>{row.id}</td>
<td>{row.name}</td>
<td>{row.age}</td>
<td>{row.city}</td>
</tr>
{/each}
</tbody>
</table>
<script lang="ts">
import type { typeDatatable } from 'svelte-datatables-net';
import { Engine, functionCreateDatatable, Pagination, RowsPerPage, Search, Sort } from 'svelte-datatables-net';
type typeData = {
brand: string;
category: string;
description: string;
discountPercentage: number;
id: number;
images: string[];
price: number;
rationg: number;
stock: number;
thumbnail: string;
title: string;
};
let objectDatatable: typeDatatable<typeData>;
const functionReadData = async function () {
const responseData = await fetch('https://dummyjson.com/products');
const jsonData = await responseData.json();
const arrayData = jsonData.products as typeData[];
objectDatatable = functionCreateDatatable({
parData: arrayData,
parSearchableColumns: ['id', 'brand', 'category', 'description'],
parRowsPerPage: '10',
parSearchString: '',
parSortBy: 'id',
parSortOrder: 'ascending'
});
};
</script>
{#await functionReadData()}
READING DATA...
{:then}
<Engine bind:propDatatable={objectDatatable} />
<p>
<span>Search:</span>
<Search bind:propDatatable={objectDatatable} propPlaceholder="Type here..." />
</p>
<p>
<RowsPerPage bind:propDatatable={objectDatatable}>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="all">ALL</option>
</RowsPerPage>
<span>RESULTS PER PAGE</span>
</p>
<p>
<Pagination bind:propDatatable={objectDatatable} propSize="small" />
</p>
<table>
<thead>
<tr>
<th>
<Sort bind:propDatatable={objectDatatable} propColumn={'id'}>ID (click here)</Sort
>
</th>
<th>
<Sort bind:propDatatable={objectDatatable} propColumn={'brand'}
>BRAND (click here)</Sort
>
</th>
<th>CATEGORY</th>
<th>DESCRIPTION</th>
<th>STOCK</th>
</tr>
</thead>
<tbody>
{#each objectDatatable.arrayData as row}
<tr>
<td>{row.id}</td>
<td>{row.brand}</td>
<td>{row.category}</td>
<td>{row.description}</td>
<td>{row.stock}</td>
</tr>
{/each}
</tbody>
</table>
{/await}
<script lang="ts">
import { Engine, functionCreateDatatable, Pagination, RowsPerPage, Search, Sort } from 'svelte-datatables-net';
const arrayUsers = [
{ id: 9, name: 'Denzel', age: 24, city: 'Newcastle' },
{ id: 12, name: 'Olga', age: 35, city: 'Las Cruces' },
{ id: 13, name: 'Barry', age: 27, city: 'Newport' },
{ id: 10, name: 'Anthony', age: 47, city: 'Los Banos' },
{ id: 2, name: 'Mary', age: 45, city: 'Los Angeles' },
{ id: 1, name: 'John', age: 21, city: 'New York' },
{ id: 3, name: 'Mark', age: 23, city: 'Boston' },
{ id: 5, name: 'Brian', age: 22, city: 'New Orleans' },
{ id: 14, name: 'Larry', age: 41, city: 'Los Altos' },
{ id: 4, name: 'Cris', age: 32, city: 'Las Vegas' },
{ id: 6, name: 'Stuart', age: 46, city: 'Los Gatos' },
{ id: 7, name: 'Owen', age: 24, city: 'Boston' },
{ id: 8, name: 'Paul', age: 33, city: 'Las Vegas' },
{ id: 11, name: 'Fred', age: 25, city: 'Boston' },
{ id: 15, name: 'Richard', age: 29, city: 'Boston' },
{ id: 16, name: 'Bruna', age: 31, city: 'Las Vegas' }
];
let objectDatatable = functionCreateDatatable({
parData: arrayUsers,
parSearchableColumns: ['name', 'city'],
parRowsPerPage: '5',
parSearchString: '',
parSortBy: 'city',
parSortOrder: 'ascending'
});
</script>
<svelte:head>
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
</svelte:head>
<Engine bind:propDatatable={objectDatatable} />
<div class="container-sm">
<div class="mx-3">
<!-- SEARCH & RESULTS PER PAGE -->
<div class="row align-items-center mb-2">
<div class="col-12 col-md-6 text-md-start text-center mb-1 mb-md-0">
<div class="d-md-flex align-items-md-center">
<span class="me-1">Search:</span>
<Search
bind:propDatatable={objectDatatable}
propPlaceholder="Type here..."
class="form-control form-control-sm"
/>
</div>
</div>
<div class="col-12 col-md-6 text-md-end text-center">
<RowsPerPage
bind:propDatatable={objectDatatable}
class="d-inline form-select form-select-sm w-auto"
>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="all">ALL</option>
</RowsPerPage>
<span>RESULTS PER PAGE</span>
</div>
</div>
<!---->
{#if objectDatatable.arraySearched.length === 0}
<div class="text-center mt-5"><strong>NO RECORDS FOUND.</strong></div>
{:else}
<!-- TABLE -->
<table class="table table-striped table-sm mt-2">
<thead>
<tr>
<th>
<Sort bind:propDatatable={objectDatatable} propColumn={'id'}>ID</Sort>
</th>
<th>
<Sort bind:propDatatable={objectDatatable} propColumn={'name'}>NAME</Sort>
</th>
<th>AGE</th>
<th>CITY</th>
</tr>
</thead>
<tbody>
{#each objectDatatable.arrayData as row}
<tr>
<td>{row.id}</td>
<td>{row.name}</td>
<td>{row.age}</td>
<td>{row.city}</td>
</tr>
{/each}
</tbody>
</table>
<!---->
<!-- PAGINATION -->
<div class="d-flex justify-content-center justify-content-md-end mb-5">
<Pagination bind:propDatatable={objectDatatable} propSize="default" />
</div>
<!---->
{/if}
</div>
</div>
Once you've created a project and installed dependencies with npm install
, start a development server:
npm run dev
FAQs
svelte-datatables-net is a svelte/sveltekit component that turns data into an interactive HTML table. Inspired by datatables.net.
The npm package svelte-datatables-net receives a total of 134 weekly downloads. As such, svelte-datatables-net popularity was classified as not popular.
We found that svelte-datatables-net demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.