i want to include an HTML table in an own Icinga Web 2 Module. This table has periodically changing elements (for example services) and it shall be possible to multiselect entries and perform than an action over them.
What is there / Background
Tables have multiselect feature like it is implemented in monitoring/list/services. The entries in the table there can be “multiselected” and a controller / with specified script view is opened in a new IW2 column with a summary of all selection. Thats very nice.
How is it specified in monitoring module (taken from services.phtml):
<table data-base-target="_next" class="table-row-selectable state-table multiselect" data-icinga-multiselect-url="<?= $this->href('monitoring/services/show') ?>" data-icinga-multiselect-controllers="<?= $this->href('monitoring/services') ?>" data-icinga-multiselect-data="service,host"> ... <tr href="/icingaweb2/ ... ?host=<host_name>&service=<service_name>"> ... </tr> </table>
The parameter of the url of the target contains all elements: ((host=<…>&service=<…>)|(host…)|…)
What i need:
I don’t want Icinga Web 2 to open a new Column with the selection. I want Icinga Web 2 to mark the selected entries (with class active) and get in the view script the information about which elements are selected and which not in order to perform an action about this objects.
What i have tried
Create an extra div inside the own view script to have it as target:
<div id="mutliselect-target"/> ... <table data-base-target="multiselect-target" class="table-row-selectable multiselect" data-icinga-multiselect-url="<?= $this->href('<own_module>/<multiselect_controller>/<view_with_action_button>') ?>" data-icinga-multiselect-controllers="<?= $this->href('<own_module>/<multiselect_controller>) ?>" data-icinga-multiselect-data="service,host"> ... <tr href="/icingaweb2/ ... ?host=<host_name>&service=<service_name>">
This has worked somehow. The Multiselect controller has been opened in the desired div but the selection of the entries was often broken (after autorefresh). For example active entries couldn’t be deactivated anymore. So control was not possible.
Remark: When i changed the target to “_next” the handling has worked.
What did also not work because the own site is overritten on every click:
<table data-base-target="_self" ...> ... </table>
But that is somehow clear since you crash your selection.
So does someone has an idea how to use this great feature of multiselection in this case where you don’t want to open an extra “column”.
If the information is in the url parameters and the table (in the same view script) can still be controlled (set elements active / dactive) then everything is fine.