Dynamic Table
Usage
The simplest usage of ShDynamicTable can be shown in the following example:
Dymanic Table example
- female17
- male13
- 221
- 241
- 251
- 261
- 272
- 282
- 292
- 302
- 312
- 322
- 332
- 341
- 352
- 361
- 371
- 382
- 391
- 401
- 411
- 421
- 451
Emily | Johnson | emilys | emily.johnson@x.dummyjson.com | female | 1996-5-30 | |
Michael | Williams | michaelw | michael.williams@x.dummyjson.com | male | 1989-8-10 | |
Sophia | Brown | sophiab | sophia.brown@x.dummyjson.com | female | 1982-11-6 | |
James | Davis | jamesd | james.davis@x.dummyjson.com | male | 1979-5-4 | |
Emma | Miller | emmaj | emma.miller@x.dummyjson.com | female | 1994-6-13 | |
Olivia | Wilson | oliviaw | olivia.wilson@x.dummyjson.com | female | 2002-4-20 | |
Alexander | Jones | alexanderj | alexander.jones@x.dummyjson.com | male | 1986-10-20 | |
Ava | Taylor | avat | ava.taylor@x.dummyjson.com | female | 1997-8-25 | |
Ethan | Martinez | ethanm | ethan.martinez@x.dummyjson.com | male | 1991-2-12 | |
Isabella | Anderson | isabellad | isabella.anderson@x.dummyjson.com | female | 1993-6-10 |
Copyright © 2024
To achieve the above the following code needs do be inserted in your Markdown text.
::ShDynamicTable
---
dataUrl: "http://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 | false
value indication that if the field in question should be used for quick filtersquery
-true | false
value indicating if this filed should be used in query searchsortable
-true | false
value indication if this field should be used for ordering the datatype
- one of the following[text, number, date]
values defining the type of the field value
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.
Properties
Property | Attribute | Default | Description |
---|---|---|---|
ui |
n/a | n/a | Allows detailed customization of styling for various elements of the table component. Attributes include wrapper , header , footer , etc., for granular control over appearance. |
wrapper |
config.wrapper |
Customizes the overall container's styling, such as padding, margin, and background. | |
base |
config.base |
Applies default styles to the main table structure, including borders and layout. | |
header |
config.header |
Styles for the table's header, including background, text alignment, and font. | |
footer |
config.footer |
Customizes the footer section, often used for summaries or additional actions. | |
pagination |
config.pagination |
Styles pagination controls, including buttons, spacing, and hover effects. | |
search |
config.search |
Defines styling for the search input or controls, enhancing usability and design. | |
filter |
config.filter |
Applies styles to filtering options for better UI clarity and interaction. | |
table |
config.table |
Styling applied to the table element, such as borders, spacing, and layout. | |
thead |
config.thead |
Customizes the table header section, including fonts, colors, and spacing. | |
tr.base tr.selected tr.active
|
config.tr.base config.tr.selected config.tr.active
|
Defines row-level styles for default, selected, and active states. | |
th.base th.padding th.color th.font th.size
|
config.th.base config.th.padding config.th.color config.th.font config.th.size
|
Applies header cell-level styles, such as padding, font, color, and size. | |
td.base td.padding td.color td.font td.size
|
config.td.base config.td.padding config.td.color config.td.font config.td.size
|
Customizes data cell styles, including spacing, text size, and color. | |
dataUrl |
n/a | n/a | URL from which the table fetches its data dynamically. |
dataField |
n/a | n/a | Specifies the key or field within the fetched data to be displayed. |
columns |
name title filter query sortable hide type
|
n/a n/a true | false true | false true | false true | false n/a |
Defines column properties, including header titles, filters, and sort options. |
header |
n/a | n/a | Content for the table header, typically displayed above the column titles. |
footer |
n/a | n/a | Content for the footer section, often used for totals or additional information. |
perPage |
n/a | 10 |
Defines the number of rows per page. Acceptable values: 10, 25, 50, 100. |
Config
These style properties can be modified via ui
and are stored in the ShDynamicTable.ts
file:
export default {
wrapper: "bg-gray-50 dark:bg-inherit border-2 border-neutral-200 dark:border-neutral-500 rounded-2xl p-5",
header: "font-semibold text-center bg-slate-200 dark:bg-slate-700 dark:text-slate-200",
base: "",
footer: "font-semibold text-center bg-slate-200 dark:bg-slate-700 dark:text-slate-200",
search: "pb-4",
filter: "",
table: 'min-w-full divide-y divide-gray-300 dark:divide-gray-700',
tbody: 'divide-y divide-gray-300 dark:divide-gray-700',
thead: "",
tr: {
base: '',
selected: 'bg-oma-blue-400 hover:bg-oma-blue-300 text-white dark:bg-oma-blue-600 dark:hover:bg-oma-blue-500 dark:text-golden',
active: 'hover:bg-neutral-200 dark:hover:bg-neutral-600 cursor-pointer'
},
th: {
base: 'text-left rtl:text-right dark:bg-neutral-600',
padding: 'px-4 py-3.5',
color: 'text-gray-900 dark:text-white',
font: 'font-semibold',
size: 'text-sm'
},
td: {
base: 'whitespace-nowrap text-pretty ',
padding: 'px-4 py-4',
color: 'text-gray-500 dark:text-gray-400',
font: '',
size: 'text-sm'
},
pagination: '',
perPage: [10, 25, 50, 100],
default: {
perPage: 10,
sortAscIcon: 'i-heroicons-bars-arrow-up-20-solid',
sortDescIcon: 'i-heroicons-bars-arrow-down-20-solid',
sortButton: {
icon: 'i-heroicons-arrows-up-down-20-solid',
trailing: true,
square: true,
color: 'gray' as const,
variant: 'ghost' as const,
class: '-m-1.5 font-semibold text-sm'
},
}
}
Class Descriptions
These represent the class values utilized in the ShDynamicTable component. These values are customizable and can be strengthened or overridden through the ui
properties' attributes.
wrapper
- Value:
"bg-gray-50 dark:bg-inherit border-2 border-neutral-200 dark:border-neutral-500 rounded-2xl p-5"
- Description: Defines the overall container styles. The value "bg-gray-50 dark:bg-inherit border-2 border-neutral-200 dark:border-neutral-500 rounded-2xl p-5" applies a light background (bg-gray-50), inherits background color in dark mode (dark:bg-inherit), adds a 2-unit border (border-2), adjusts border color for dark mode (dark:border-neutral-500), rounds corners (rounded-2xl), and adds padding of 5 units (p-5).
header
- Value:
"font-semibold text-center bg-slate-200 dark:bg-slate-700 dark:text-slate-200"
- Description: Styles the header section. The value "font-semibold text-center bg-slate-200 dark:bg-slate-700 dark:text-slate-200" sets a semi-bold font weight (font-semibold), centers the text (text-center), applies a light slate background (bg-slate-200), adjusts background color for dark mode (dark:bg-slate-700), and changes text color for dark mode (dark:text-slate-200).
base
- Value:
""
- Description: Serves as a base for custom styles, currently left empty for flexibility.
footer
- Value:
"font-semibold text-center bg-slate-200 dark:bg-slate-700 dark:text-slate-200"
- Description: Defines styles for the footer. Similar to the header, the value sets a semi-bold font weight (font-semibold), centers text (text-center), applies a slate background (bg-slate-200), and adapts colors for dark mode (dark:bg-slate-700, dark:text-slate-200).
search
- Value:
"pb-4"
- Description: Adds padding to the bottom of the search section. The value "pb-4" applies 4 units of bottom padding.
filter
- Value:
""
- Description: Provides a base for filter-specific styles, currently left empty for customization.
table
- Value:
"min-w-full divide-y divide-gray-300 dark:divide-gray-700"
- Description: Styles the table container. The value "min-w-full divide-y divide-gray-300 dark:divide-gray-700" ensures the table spans the full width (min-w-full), adds horizontal dividers (divide-y), and adjusts divider color for dark mode (dark:divide-gray-700).
tbody
- Value:
"divide-y divide-gray-300 dark:divide-gray-700"
- Description: Styles the table body. The value adds horizontal dividers (divide-y), with adjustments for light and dark mode (divide-gray-300, dark:divide-gray-700).
thead
- Value:
""
- Description: A placeholder for header-specific styles, currently left empty for customization.
tr
- Base:
- Value:
""
- Description: Base styles for table rows, currently left empty.
- Value:
- Selected:
- Value:
"bg-oma-blue-400 hover:bg-oma-blue-300 text-white dark:bg-oma-blue-600 dark:hover:bg-oma-blue-500 dark:text-golden"
- Description: Applies styles for selected rows. Includes a blue background (bg-oma-blue-400), hover effect (hover:bg-oma-blue-300), white text color (text-white), and dark mode adaptations (dark:bg-oma-blue-600, dark:hover:bg-oma-blue-500, dark:text-golden).
- Value:
- Active:
- Value:
"hover:bg-neutral-200 dark:hover:bg-neutral-600 cursor-pointer"
- Description: Adds hover effects and pointer cursor. The value changes the background on hover (hover:bg-neutral-200, dark:hover:bg-neutral-600) and sets the cursor to pointer (cursor-pointer).
- Value:
th
- Base:
- Value:
"text-left rtl:text-right dark:bg-neutral-600"
- Description: Sets text alignment (text-left, rtl:text-right) and applies a background for dark mode (dark:bg-neutral-600).
- Value:
- Padding:
- Value:
"px-4 py-3.5"
- Description: Adds padding of 4 units horizontally (px-4) and 3.5 units vertically (py-3.5).
- Value:
- Color:
- Value:
"text-gray-900 dark:text-white"
- Description: Defines text colors for light and dark modes.
- Value:
- Font:
- Value:
"font-semibold"
- Description: Sets a semi-bold font weight.
- Value:
- Size:
- Value:
"text-sm"
- Description: Defines the font size as small (text-sm).
- Value:
td
- Base:
- Value:
"whitespace-nowrap text-pretty"
- Description: Ensures text does not wrap (whitespace-nowrap) and applies a custom style class (text-pretty).
- Value:
- Padding:
- Value:
"px-4 py-4"
- Description: Adds padding of 4 units both horizontally and vertically.
- Value:
- Color:
- Value:
"text-gray-500 dark:text-gray-400"
- Description: Sets text colors for light and dark modes.
- Value:
- Font:
- Value:
""
- Description: Placeholder for custom font styles.
- Value:
- Size:
- Value:
"text-sm"
- Description: Defines the font size as small (text-sm).
- Value:
pagination
- Value:
""
- Description: Placeholder for pagination-specific styles.
perPage
- Value:
[10, 25, 50, 100]
- Description: Defines available options for items per page.
default
- Value: An object containing default configuration:
perPage
: 10sortAscIcon
:'i-heroicons-bars-arrow-up-20-solid'
sortDescIcon
:'i-heroicons-bars-arrow-down-20-solid'
sortButton
:icon
:'i-heroicons-arrows-up-down-20-solid'
trailing
:true
square
:true
color
:'gray'
variant
:'ghost'
class
:'-m-1.5 font-semibold text-sm'
- Description: Holds default configuration values for pagination and sorting icons, with button styles defined by "sortButton" properties.