Table
<p-table> | PTable
The Table component is used to display data in a table format.
<p-table class="table-example" > </p-table> <script> const table = document.querySelector('.table-example'); table.loading = true; table.options = { paginate: true, selectable: true, columns: [{field: 'name', id: 'name', headerName: 'Full name', alignItems: 'center', justifyContent: 'flex-start', resizable: true, width: '150px', minWidth: '120px', maxWidth: '300px' },{field: 'age', id: 'age', headerName: 'Age', },{field: 'address.street', id: 'street', headerName: 'Street', maxWidth: '400px', },{field: 'address.department', id: 'department', headerName: 'Department', },{field: 'address.city', id: 'city', headerName: 'City', },{field: 'address.country', id: 'country', headerName: 'Country', }, {field: 'status', id: 'status', headerName: 'Status', render: (row) => `${String(row.status) == '1' ? 'Active' : 'Inactive'}`, justifyContent: 'center', } ] } setTimeout(() => { table.data = [{ "name": "Alice", "age": "28", "address": { "street": "2 Elm Street", "department": "Greenwood", "city": "Portland", "country": "USA" }, "status": 1 }, { "name": "Bob", "age": "35", "address": { "street": "3 Oak Street", "department": "Lakeside", "city": "Chicago", "country": "USA" }, "status": 0 }, { "name": "Charlie", "age": "22", "address": { "street": "4 Pine Street", "department": "Downtown", "city": "San Francisco", "country": "USA" }, "status": 1 }, { "name": "David", "age": "40", "address": { "street": "5 Maple Street", "department": "Westside", "city": "Los Angeles", "country": "USA" }, "status": 0 }, { "name": "Eva", "age": "31", "address": { "street": "6 Birch Street", "department": "Riverside", "city": "Austin", "country": "USA" }, "status": 1 }, { "name": "Frank", "age": "29", "address": { "street": "7 Cedar Street", "department": "Northside", "city": "Denver", "country": "USA" }, "status": 0 }, { "name": "Grace", "age": "33", "address": { "street": "8 Willow Street", "department": "Southside", "city": "Miami", "country": "USA" }, "status": 1 }, { "name": "Hannah", "age": "25", "address": { "street": "9 Walnut Street", "department": "Eastside", "city": "Boston", "country": "USA" }, "status": 0 }, { "name": "Ivy", "age": "27", "address": { "street": "10 Chestnut Street", "department": "Central", "city": "Philadelphia", "country": "USA" }, "status": 1 }, { "name": "Jack", "age": "32", "address": { "street": "11 Ash Street", "department": "Uptown", "city": "Atlanta", "country": "USA" }, "status": 0 }, { "name": "Karen", "age": "36", "address": { "street": "12 Fir Street", "department": "Midtown", "city": "Seattle", "country": "USA" }, "status": 1 }, { "name": "Leo", "age": "24", "address": { "street": "13 Poplar Street", "department": "Parkside", "city": "San Diego", "country": "USA" }, "status": 0 }, { "name": "Mia", "age": "26", "address": { "street": "14 Sycamore Street", "department": "Harbor", "city": "San Jose", "country": "USA" }, "status": 1 }, { "name": "Nina", "age": "29", "address": { "street": "15 Magnolia Street", "department": "Hilltop", "city": "Las Vegas", "country": "USA" }, "status": 0 }, { "name": "Oliver", "age": "31", "address": { "street": "16 Hickory Street", "department": "Downtown", "city": "Orlando", "country": "USA" }, "status": 1 }, { "name": "Paula", "age": "37", "address": { "street": "17 Locust Street", "department": "Sunset", "city": "Honolulu", "country": "USA" }, "status": 0 }, { "name": "Quinn", "age": "23", "address": { "street": "18 Elm Street", "department": "Springfield", "city": "New York", "country": "USA" }, "status": 1 }, { "name": "Rachel", "age": "34", "address": { "street": "19 Redwood Street", "department": "Elmwood", "city": "Washington", "country": "USA" }, "status": 0 }, { "name": "Steve", "age": "38", "address": { "street": "20 Oak Street", "department": "Creekside", "city": "Dallas", "country": "USA" }, "status": 1 }] table.options = JSON.parse(JSON.stringify(table.options)); table.loading = false; }, 3000); </script>
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.2.15/cdn/components/table/table.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.2.15/cdn/components/table/table.js';
To import this component using a bundler:
import 'pure-uikit/dist/components/table/table.js';
To import this component as a React component:
import PTable from 'pure-uikit/dist/react/table';
Slots
Name | Description |
---|---|
(default) | The default slot. |
paginate
|
An optional slot for paginate element. |
Learn more about using slots.
Properties
Name | Description | Reflects | Type | Default |
---|---|---|---|---|
disabled
|
Indicates that the element is disabled. |
|
boolean
|
false
|
options
|
The options for the table. |
|
TableOptions
|
{ columns: [], paginate: true, draggable: false, hideHeader: false, hideFooter: false,
expandable: false, selectable: false, }
|
data
|
The data to display in the table. This property is an array of objects, where each object represents
a row in the table. The properties of each object will be used to populate the columns in the table.
The column headers will be determined by the
options.columns property.
|
|
TableRowData[]
|
[]
|
loading
|
Whether the table is currently loading data. |
|
boolean
|
false
|
page
|
The current page of items based on the current limit and total . |
|
number
|
1
|
limit
|
The number of items to display per page. |
|
number
|
10
|
total
|
The total number of items in the table. |
|
number
|
0
|
currentItems
|
Returns the current page of items based on the current page, page size, and total items. If the table is not local paginated, all items are returned. | - | - | |
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
Name | React Event | Description | Event Detail |
---|---|---|---|
p-change |
onPChange |
Emitted when the current page value changes. | - |
p-table-row-select |
onPTableRowSelect |
Emitted when the rows selected changed. | - |
Learn more about events.
Custom Properties
Name | Description | Default |
---|---|---|
--table-header-cell-padding |
Set padding for header cell. | |
--table-body-cell-padding |
Set padding for body cell. | |
--table-footer-padding |
Set padding for footer cell. | |
--table-border-horizontal-width |
Set border width horizontal. | |
--table-border-horizontal-style |
Set border style horizontal. | |
--table-border-horizontal-color |
Set border color horizontal. | |
--table-border-vertical-width |
Set border width vertical. | |
--table-border-vertical-style |
Set border style vertical. | |
--table-border-vertical-color |
Set border color vertical. | |
--table-border-width |
Set table border width. | |
--table-border-color |
Set table border color. | |
--table-border-style |
Set table border style. | |
--table-border-radius |
Set table border radius. | |
--table-row-hover-background-color |
Set table row hover background color. | |
--table-cell-background-color |
Set table cell background color. | |
--table-cell-hover-background-color |
Set table cell hover background color. | |
--table-cell-min-height |
Set table cell min height. | |
--table-cell-max-height |
Set table cell max height. | |
--table-cell-min-width |
Set table cell min width. | |
--table-cell-max-width |
Set table cell max width. |
Learn more about customizing CSS custom properties.
Parts
Name | Description |
---|---|
table-wrapper |
The component’s table wrapper. |
table-header |
The component’s table header wrapper. |
table-body |
The component’s table body wrapper. |
table-loading |
The component’s table loading wrapper. |
table-empty |
The component’s table empty wrapper. |
table-footer |
The component’s table footer wrapper. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.
<p-button>
<p-icon>
<p-icon-button>
<p-paginate>
<p-spinner>
<p-tag>