This component is meant to help make tables responsive by eliminating columns (from the right) as the screen width reduces. When there are hidden columns, the last column header becomes a dropdown button allowing the selection of another column to be displayed instead.
The only required prop is an items
array of objects. Column headers will automatically be detected from object keys if no column configuration is present.
A config
prop allows you to pass an array of column definitions. If passed, only these columns will appear, other keys in your items
objects will be ignored.
key: string
corresponds to object key in youritems
objectstitle?: string
a display name for this column's headerwidth?: number
a guess at how wide in pixels this column will be; helps decide when to hide columns, default 150neverhide?: boolean
setting to make sure this column is never hidden; good to set on the column that is most identifying for each row, like a name. by default the leftmost column will stick around as identifyingbodyCellClass?: string
CSS class to set ontd
elements in the body areaheaderCellClass?: string
CSS class to set ontd
elements in the header row
tableClass
CSS class for thetable
bodyRowClass
CSS class fortr
in the body areabodyCellClass
CSS class fortd
in the body area, additional to the one set in column configheaderRowClass
CSS class fortr
on the header rowheaderCellClass
CSS class forth
in the header row, additional to the one set in column configmenuClass
CSS class for theul
dropdown menumenuItemClass
CSS class forli
in the dropdown menumenuItemHilitedClass
CSS class forli
in the dropdown menu when they are currently hilited/activedefaultCellWidth
, guess for any column width in pixels, allows you to hide columns earlier/later, default 150PopupMenu
- ???stickyheader: boolean
(defaultfalse
) - Set this totrue
if you want column headers to use a sticky positioning as the table is scrolled.
Lots of slots are provided for extra configuration.
The default slot is used for each table cell in the body area. It is optional and falls back to {value}. Because of the way slots work, your slot content will be executed in every cell. So if you need to do something special for just one cell, you have to use an if/else block to identify the special cell, falling back to {value} for everything else:
<CollapsingTable items={myItems} let:item let:key let:value>
{#if key === 'myspecialkey'}
<MySpecialComponent>{value}</MySpecialComponent>
{:else}
{value}
{/if}
</CollapsingTable>
The slot props are item
, key
, and value
.
A slot named headercell
allows you to do the same thing for cells in the header row that the
default slot allows for body cells.
<CollapsingTable items={myItems} let:column let:key let:title>
<div slot="headercell">
{#if key === 'myspecialkey'}
<MySpecialComponent>{title}</MySpecialComponent>
{:else}
{title}
{/if}
</div>
</CollapsingTable>
The slot props are column
, key
, and title
. column
is the configuration object for the
current column, title
is column.title || column.key
. The title/key will be used as fallback
content if you do not specify a header slot.
A slot is provided for you to provide a custom icon for the column header that is serving as the dropdown button.
<CollapsingTable items={myItems}>
<i type='fa caret-down' slot="dropicon" aria-hidden="true"></i>
</CollapsingTable>