caption
property doesn't display the caption but instead can be used to improve accessibility of the table.<!doctype html>
<html lang="en" class="auto">
<head>
<title></title>
</head>
<body class="bg-base">
<p-table caption="Some caption">
<p-table-head>
<p-table-head-row>
<p-table-head-cell>
Column 1
</p-table-head-cell>
<p-table-head-cell>
Column 2
</p-table-head-cell>
<p-table-head-cell>
Column 3
</p-table-head-cell>
</p-table-head-row>
</p-table-head>
<p-table-body>
<p-table-row>
<p-table-cell>
Cell 1
</p-table-cell>
<p-table-cell>
Cell 2
</p-table-cell>
<p-table-cell>
Cell 3
</p-table-cell>
</p-table-row>
</p-table-body>
</p-table>
<script>
</script>
</body>
</html>
caption
slot its content will be rendered while offering full control of appearance.<!doctype html>
<html lang="en" class="auto">
<head>
<title></title>
</head>
<body class="bg-base">
<p-table>
<p-heading slot="caption" size="large">
Some slotted caption
</p-heading>
<p-table-head>
<p-table-head-row>
<p-table-head-cell>
Column 1
</p-table-head-cell>
<p-table-head-cell>
Column 2
</p-table-head-cell>
<p-table-head-cell>
Column 3
</p-table-head-cell>
</p-table-head-row>
</p-table-head>
<p-table-body>
<p-table-row>
<p-table-cell>
Cell 1
</p-table-cell>
<p-table-cell>
Cell 2
</p-table-cell>
<p-table-cell>
Cell 3
</p-table-cell>
</p-table-row>
</p-table-body>
</p-table>
<script>
</script>
</body>
</html>
layout
to fixed
you can get full control over every column width that are otherwise controlled by their
content. An identical width
, min-width
and/or max-width
depending on what you want to achieve, has to be specified
on every p-table-head-cell
and p-table-cell
within the same column.width
units likes 50%
or 50vw
, these may lead to unexpected results when the
table is scrollable especially on smaller screens or when combined with absolute (e.g. 50px
) or default auto values
(based on content).<p-text ellipsis>Some content</p-text>
.title
attribute or custom tooltip.<!doctype html>
<html lang="en" class="auto">
<head>
<title></title>
</head>
<body class="bg-base">
<p-table caption="Some caption" layout="fixed">
<p-table-head>
<p-table-head-row>
<p-table-head-cell class="w-[50%] max-w-[50%]">
Column 1 (50%)
</p-table-head-cell>
<p-table-head-cell class="w-[150px] max-w-[150px]">
Column 2 (150px)
</p-table-head-cell>
<p-table-head-cell>
Column 3 (auto)
</p-table-head-cell>
</p-table-head-row>
</p-table-head>
<p-table-body>
<p-table-row>
<p-table-cell class="w-[50%] max-w-[50%]">
Cell 1
</p-table-cell>
<p-table-cell class="w-[150px] max-w-[150px]">
Cell 2
</p-table-cell>
<p-table-cell>
Cell 3
</p-table-cell>
</p-table-row>
<p-table-row>
<p-table-cell class="w-[50%] max-w-[50%]">
Cell 1
</p-table-cell>
<p-table-cell class="w-[150px] max-w-[150px]">
<p-text ellipsis="true" title="Cell 2 with more content">
Cell 2 with more content
</p-text>
</p-table-cell>
<p-table-cell>
Cell 3
</p-table-cell>
</p-table-row>
</p-table-body>
</p-table>
<script>
</script>
</body>
</html>
p-table
's head can be configured by setting one or more of the following properties on each p-table-head-cell
.sort
property.
It has the following structure:type TableHeadCellSort = {
id: string; // identifier for the column to be sorted by
active: boolean;
direction: 'asc' | 'desc';
};
p-table-head-cell
element, the p-table
emits an update
event that you should subscribe
to.sortingChange
event has been deprecated and will be removed with the next major release.Please use the
update
event instead.<!doctype html>
<html lang="en" class="auto">
<head>
<title></title>
</head>
<body class="bg-base">
<p-table caption="Some caption"></p-table>
<script>
(() => {
const headSorting = [
{ name: 'Column 1', id: 'col1' },
{ name: 'Column 2', id: 'col2' },
{ name: 'Column 3', id: 'col3' },
];
const dataSorting = [
{
col1: 'Name A',
col2: '9',
col3: '01.06.2021',
},
{
col1: 'Name Z',
col2: '1',
col3: '24.06.2021',
},
];
const renderTableHeadRow = (items) =>
[
'<p-table-head-row>',
...items.map((item) => `<p-table-head-cell>${item.name}</p-table-head-cell>`),
'</p-table-head-row>',
].join('');
const renderTableBodyRows = (items) =>
items
.map(
(item) => `
<p-table-row>
<p-table-cell>${item.col1}</p-table-cell>
<p-table-cell>${item.col2}</p-table-cell>
<p-table-cell>${item.col3}</p-table-cell>
</p-table-row>`
)
.join('');
const markup = `
<p-table-head>${renderTableHeadRow(headSorting)}</p-table-head>
<p-table-body>${renderTableBodyRows(dataSorting)}</p-table-body>`;
const table = document.querySelector('p-table');
table.innerHTML = markup;
const tableHeadCells = table.querySelectorAll('p-table-head-cell');
const tableBody = table.querySelector('p-table-body');
tableHeadCells.forEach((cell, index) => {
cell.sort = { id: index.toString(), active: false, direction: 'asc' };
});
table.addEventListener('update', (e) => {
const { id, direction } = e.detail;
tableHeadCells.forEach((cell, index) => {
cell.sort = {
id: index.toString(),
active: index === Number(id),
direction: index === Number(id) ? direction : 'asc',
};
});
const rows = Array.from(tableBody.querySelectorAll('p-table-row'));
const sortedRows = rows.sort((a, b) => {
const aText = a.querySelectorAll('p-table-cell')[id].textContent.trim();
const bText = b.querySelectorAll('p-table-cell')[id].textContent.trim();
const compare = aText.localeCompare(bText);
return direction === 'asc' ? compare : -compare;
});
sortedRows.forEach(row => tableBody.appendChild(row));
});
})();
</script>
</body>
</html>
hide-label
property.<!doctype html>
<html lang="en" class="auto">
<head>
<title></title>
</head>
<body class="bg-base">
<p-table caption="Some caption">
<p-table-head>
<p-table-head-row>
<p-table-head-cell>
Column 1
</p-table-head-cell>
<p-table-head-cell>
Column 2
</p-table-head-cell>
<p-table-head-cell hide-label="true">
Column 3
</p-table-head-cell>
</p-table-head-row>
</p-table-head>
<p-table-body>
<p-table-row>
<p-table-cell>
Cell 1
</p-table-cell>
<p-table-cell>
Cell 2
</p-table-cell>
<p-table-cell>
Cell 3
</p-table-cell>
</p-table-row>
</p-table-body>
</p-table>
<script>
</script>
</body>
</html>





<!doctype html>
<html lang="en" class="auto">
<head>
<title></title>
</head>
<body class="bg-base">
<p-table>
<p-heading slot="caption" variant="large" tag="h3">Some visual caption</p-heading>
<p-table-head></p-table-head>
<p-table-body></p-table-body>
</p-table>
<script></script>
</body>
</html>