Each table keeps its data before JavaScript loads or if the module fails. Enhancement adds a native popover with labeled checkboxes; at least one selectable column stays visible. Focus a table region and use the arrow keys to scroll wider data.
Basic Example
A simple table with removable columns. By default, all removable columns are shown.
Basic Usage
<table-modifiable removable="Name,Email,Phone"
role="region" aria-label="Contact table" tabindex="0">
<table>
<caption>Contact directory</caption>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>555-1234</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>jane@example.com</td>
<td>555-5678</td>
</tr>
</tbody>
</table>
</table-modifiable>
| Name | Phone | |
|---|---|---|
| John Doe | john@example.com | 555-1234 |
| Jane Smith | jane@example.com | 555-5678 |
| Bob Johnson | bob@example.com | 555-9012 |
Initial Column Visibility
Use the start-with attribute to specify which
columns should be visible initially.
Hiding Columns by Default
<table-modifiable
removable="Product,Price,Stock,Category,Supplier"
start-with="Product,Price"
role="region" aria-label="Product table" tabindex="0">
<table>
<caption>Product pricing and stock</caption>
<!-- table content -->
</table>
</table-modifiable>
| Product | Price | Stock | Category | Supplier |
|---|---|---|---|---|
| Widget | $9.99 | 42 | Tools | Acme Corp |
| Gadget | $19.99 | 15 | Electronics | Tech Supply |
| Doohickey | $4.99 | 128 | Parts | Parts Plus |
Localized Labels and a Custom Palette
Customize the button and popover labels using the
button-label, button-aria-label,
and tools-label attributes. Column names come
from your table. The shared author stylesheet uses
--table-modifiable-tool-bg and
--table-modifiable-tool-color together for the
popover; the component itself injects no colors or CSS. This
example retains the blue control theme with an explicit
light popover pair and French text.
Customized Interface
<style>
.custom-controls {
--table-modifiable-tool-bg: #fff;
--table-modifiable-tool-color: #333;
color-scheme: light;
}
.custom-controls .modification-tools-toggle {
background: #0969da;
color: #fff;
}
</style>
<table-modifiable class="custom-controls" lang="fr"
removable="Nom,Courriel,Téléphone,Adresse"
start-with="Nom,Courriel"
button-label="Choisir les colonnes"
button-aria-label="Choisir les colonnes du personnel"
tools-label="Colonnes à afficher"
role="region" aria-label="Tableau du personnel" tabindex="0">
<table>
<caption>Coordonnées du personnel</caption>
<!-- table content -->
</table>
</table-modifiable>
| Nom | Courriel | Téléphone | Adresse |
|---|---|---|---|
| Alice Anderson | alice@example.com | 555-0101 | 123 Oak St |
| Bob Brown | bob@example.com | 555-0202 | 456 Pine Ave |
| Carol Clark | carol@example.com | 555-0303 | 789 Elm Rd |
Event Handling
Listen to the table-modifiable:change event to
be notified when columns are toggled.
Event Listener Demo
<table-modifiable
id="event-demo"
removable="First Name,Last Name,Department"
role="region" aria-label="Event example table" tabindex="0">
<!-- table -->
</table-modifiable>
<script>
document.querySelector('#event-demo')
.addEventListener('table-modifiable:change', (e) => {
console.log(e.detail);
});
</script>
| First Name | Last Name | Department |
|---|---|---|
| Alice | Anderson | Engineering |
| Bob | Brown | Sales |
| Carol | Clark | Marketing |
Event Log
Toggle columns above to see events:
API Reference
For complete documentation of attributes, events, and browser support, see the README.