Configuration

The most important part of getting your dataTable ready to be used is the proper configuration. The DataTable component accepts a config object, which has the following shape:

import type { DataTableConfig } from 'svelte-advanced-datatable';
import { ComponentType } from 'svelte-advanced-datatable'; import { UserData } from './UserData.js';

const config: DataTableConfig<UserData> = {
	type: 'userData',
	columnProperties: {
		id: {
			type: ComponentType.NUMBER
		},
		userName: {
			type: ComponentType.STRING
		}
	},
	...additionalConfigOptions
};

Configuration Reference #

The configuration has the following options:

KeyTypeDescriptionDefault Value
typestringA unique identifier/name for this dataTable. Should not contain whitespaces and non-ascii charactersrequired
columnPropertiesTableColumnConfigAn object with one key for each key in the data, containing configuration options for each table columnrequired
dataSourceIDataSourceThe data source where the dataTable requests the table data from. See Data Source Configuration for more informationrequired
dataUniquePropertyKeystringThe key of your items unique identifier. For example a user id or a counter value which increases by one for each item, as long as it’s unique for each itemrequired
messageFormatterType'config' ⎮ 'svelte-i18n'Whether to use the messageConfig or the svelte-i18n library to provide all strings used by the dataTable'config'
messageFormatterPrefixstringPrefix for every message id. Only applies to external message formatters such as the svelte-i18n formatter.''
messageConfigstringAn object containing all strings used by the dataTable, such as table headers, titles of buttons and more.
Ignored if svelte-i18n is enabled by the messageFormatterType option
required if not using svelte-i18n
additionalMessageFormatterMessageFormatterA custom message formatter which can return a replacement or undefined to default to the message provided by the internal formatter/svelte-i18nundefined
modalComponentSvelteComponentA svelte component shown when a user clicks on a row to expand itundefined
onItemClick(item: YourData) => voidAn onClick handler for a table row. Gets passed the data item which the clicked row displaysundefined
forcedSearchQueryForcedSearchQueryA search query which overwrites any values by the users current search. Can be used to apply a forced filter to the whole dataTableundefined
highlightedItemIdstring⎮ Readable<string>The identifier of any item which then gets assigned the highlighted classundefined
defaultSort{ columnKey?: string; direction?: SortDirection }Sort the table using the given key and direction by defaultundefined
enablePaginationbooleanWhether to enable or disable pagination entirely.
Watch out that the server must send all table rows at once if this is disabled.
true
showTopPaginationbooleanIf the pagination component at the top of the dataTable should be showntrue
showBottomPaginationbooleanIf the pagination component at the bottom of the dataTable should be shown. Notice that the bottom pagination is always hidden when less than 10 rows are showntrue
itemsPerPagenumberMaximum amount of rows shown on one page50
enableSearchbooleanWhether to show the search textboxtrue
searchParserISearchParserWhich search parser to use to parse the users search text into search filters, categories and moreBasicSearchTextParser