All the core components have a button that lets the user decide which columns of a table to display.
Adding this functionality to your own component is very simple and is usually a simple case of adding the code below to the tmpl
file for the table.
Look for this line of code in the php block at the top of your tmpl
file.
$wa = $this->document->getWebAssetManager();
Add the following line to your existing code.
useScript('table.columns')
Note the line ending. Your final code will look similar to this example
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('table.columns')
->useScript('multiselect');
Add the following code anywhere in the php block at the top of your tmpl
file.
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('table.columns');
Your table will need to be a valid html table with a <thead>
and each column a <th>
.
If you have multiple tables on the page and you want to prevent the script loading on one of those tables then you can add the class "columns-order-ignore" to the table.