Dynamic Table
Usage
Basic
The simplest usage of ShDynamicTable can be shown in the following example:
Dymanic Table example
Copyright © 2024
::ShDynamicTable
---
dataUrl: "https://dummyjson.com/users"
dataField: "users"
columns:
- name: "firstName"
title: "First Name"
filter: false
query: true
sortable: true
type: text
- name: "lastName"
title: "Last Name"
filter: false
query: true
sortable: true
type: text
- name: "username"
title: "username"
filter: false
query: true
sortable: true
type: text
- name: "email"
title: "Email"
filter: false
query: true
sortable: false
type: email
- name: "gender"
title: "Gender"
filter: true
sortable: true
order: true
type: text
- name: "birthDate"
title: "Birth Date"
filter: false
query: true
sortable: true
type: date
- name: "age"
title: "Age"
filter: true
query: true
sortable: true
type: number
ui:
footer: "text-sm"
header: Dymanic Table example
footer: "*Copyright © 2024*"
---
::
The important parts are the dataUrl, and columns. The prior one define the
URL from witch the data will be fetched. On the other hand, columns represent
a list of elements where each table column is described.
Each column is described using the following properties:
name- the property nametitle- the label that will be show in the column headerfilter-true | falsevalue indication that if the field in question should be used for quick filtersquery-true | falsevalue indicating if this filed should be used in query searchsortable-true | falsevalue indication if this field should be used for ordering the datatype- one of the following[text, number, date, list, url]values defining the type of the field value. Alistcolumn holds comma-separated values, and each value gets its own quick filterpill-true | falsevalue indicating that the value should be shown as a pill, meant for short status wordswrap-true | falsevalue letting the cell wrap over up to two lines instead of being cut to one (the full value is always available as a tooltip)
Numeric columns (other than identifiers whose name ends in id) are right-aligned automatically.
Data field
Beside the above the dataField parameter can be used if the data fetched
holds the table items under a specific property.
This is typical in REST API results.
You can review the one used in above example
where the items that we would like to show in the
table is stored in users field.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
dataUrlrequired | String | '' | URL from which the table fetches its data dynamically. |
dataField | String | () => undefined | Specifies the key or field within the fetched data to be displayed. |
columnsrequired | itemsElement[] | () => ([]) | Column definitions: `name` (key in the data) plus optional `title`, `filter`, `order`, `hide`, `type`, `pill`, `wrap` and more. See the Columns section of the guideline. |
ui | Record<string, any> | – | Overrides the default classes of the UI config below. Values are merged with the defaults using tailwind-merge. |
header | String | '' | Content for the table header, typically displayed above the column titles. |
footer | String | '' | Content for the footer section, often used for totals or additional information. |
perPage | number | DEFAULT_PER_PAGE | Defines the number of rows shown per page when the table loads, and preselects that value in the "Show" dropdown. Acceptable values: 10, 25, 50, 100, or `-1` to show all rows on a single page. |
transformRawData | any | () => null | Optional. Name of a built-in transform applied to the fetched data before it is rendered. Accepts `filterDDFObjects`, `filterCommonObjects`, or `filterOmaEnablers`. |
autofocusSearch | Boolean | false | When `true`, the page scrolls to the table once its data has loaded and puts the cursor in the search box, so a visitor can start typing straight away. Intended for pages whose main purpose is looking something up in the table. The scroll is skipped when the URL carries an anchor, and the focus is skipped below the `lg` breakpoint so the on-screen keyboard does not cover the table on touch devices. |
class | any | () => undefined | Additional classes applied to the root element of the component. |
Columns
Each item of the columns prop describes one column of the table:
| Field | Type | Default | Description |
|---|---|---|---|
namerequired | String | – | Key of the field in the data that this column displays. |
title | String | – | Header text of the column. Defaults to `name`. |
filter | Boolean | – | Adds a filter panel with the distinct values of the column. |
sortable | Boolean | – | Adds a sort button to the column header. |
hide | Boolean | – | Hides the column, while still allowing it to be searched. |
formatColumValue | String | – | Reformats the value before display. `DY` shows only the year of a date. |
type | String | – | How the value is rendered: `url` (link), `list` (several values) or `subs` (a field of the value). |
typeData | Array | – | Extra fields used by `type`. For `url`, the field that holds the link address. |
pill | Boolean | – | Render the value as a pill - meant for short status vocabularies. |
wrap | Boolean | – | Let the cell wrap over several lines instead of truncating to one. |
Slots
This component has no slots.
UI config
Default classes of every styled element. Override any key through the ui prop.
| Key | Default classes | Description |
|---|---|---|
wrapper | w-full bg-neutral-50 dark:bg-inherit border-2 border-neutral-200 dark:border-neutral-500 rounded-2xl p-5 | Customizes the overall container's styling, such as padding, margin, and background. |
header | rounded-xl border-2 border-neutral-300 dark:border-neutral-600 bg-neutral-100 dark:bg-neutral-800 px-6 py-4 mb-6 text-center text-lg md:text-xl font-bold uppercase tracking-[0.18em] text-black dark:text-white not-prose | Styles for the table's header, including background, text alignment, and font. |
base | w-full | Applies default styles to the main table structure, including borders and layout. |
footer | font-semibold text-center text-black dark:text-white border-t border-neutral-200 dark:border-neutral-700 pt-3 mt-5 | Customizes the footer section, often used for summaries or additional actions. |
search | w-full pb-4 | Defines styling for the search input or controls, enhancing usability and design. |
toolbar | flex flex-wrap items-center gap-2 | Row that holds the search, filters and result count. |


