-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds components for a selectable table
Fixes: OX-11093
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/resources/default/assets/tycho/scripts/selectableTable.js.pasta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
sirius.ready(function () { | ||
document.querySelectorAll('.select-all-visible-table-rows-checkbox-js').forEach(function (_selectAllCheckbox) { | ||
const _table = _selectAllCheckbox.closest('table'); | ||
// Handle changing the state of the select-all checkbox found in the table head row | ||
_selectAllCheckbox.addEventListener('change', function () { | ||
_table.querySelectorAll('.select-table-row-checkbox-js').forEach(_checkbox => { | ||
_checkbox.checked = _selectAllCheckbox.checked; | ||
toggleRowSelection(_checkbox); | ||
}); | ||
}); | ||
|
||
_table.querySelectorAll('.select-table-row-checkbox-js').forEach(function (_checkbox) { | ||
// Handle changing the state of the select-all checkbox found in the table head row | ||
// When all rows are selected, the select-all checkbox should be checked as well | ||
_checkbox.addEventListener('change', function () { | ||
toggleRowSelection(_checkbox); | ||
changeSelectAllCheckboxState(_table); | ||
}); | ||
|
||
const _tr = _checkbox.closest('tr'); | ||
// Handle clicks on the row for convenience | ||
_tr.addEventListener('click', function (event) { | ||
if (event.target.tagName.toLowerCase() !== 'input' && | ||
event.target.tagName.toLowerCase() !== 'a' && | ||
event.target.tagName.toLowerCase() !== 'button') { | ||
_checkbox.checked = !_checkbox.checked; | ||
_checkbox.dispatchEvent(new Event('change')); | ||
} | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
function toggleRowSelection(_checkbox) { | ||
const _tr = _checkbox.closest('tr'); | ||
if (_checkbox.checked) { | ||
_tr.style.backgroundColor = 'lightgray'; | ||
} else { | ||
_tr.style.backgroundColor = ''; | ||
} | ||
} | ||
|
||
function changeSelectAllCheckboxState(_table) { | ||
const allChecked = _table.querySelectorAll('.select-table-row-checkbox-js:checked').length === _table.querySelectorAll('.select-table-row-checkbox-js').length; | ||
_table.querySelectorAll('.select-all-visible-table-rows-checkbox-js').forEach(_node => { | ||
_node.checked = allChecked; | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/resources/default/taglib/t/selectableTableHeaderRow.html.pasta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<i:pragma name="description"> | ||
Adds a table header row to a selectable table. The row will contain a checkbox in the first column which can be used to select or deselect all rows. | ||
</i:pragma> | ||
|
||
<thead> | ||
<tr> | ||
<th class="align-top"> | ||
<input class="cursor-pointer select-all-visible-table-rows-checkbox-js" | ||
type="checkbox" | ||
title="@i18n('selectableTable.row.selection.all')"/> | ||
</th> | ||
<i:render name="body"/> | ||
</tr> | ||
</thead> |
19 changes: 19 additions & 0 deletions
19
src/main/resources/default/taglib/t/selectableTableRow.html.pasta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<i:arg name="entityId" type="String" description="The id of the entity to which this table row is associated with"/> | ||
|
||
|
||
<i:pragma name="description"> | ||
Renders a table row which can be selected by the user. The row will have a checkbox in the first column. | ||
The checkbox visualizes the selection state of the row and can be used to select or deselect the row. | ||
The table row can also be selected by simply clicking on it. | ||
Note: Links and buttons in the row will not trigger the selection of the row. | ||
</i:pragma> | ||
|
||
<tr class="cursor-pointer"> | ||
<td> | ||
<input class="cursor-pointer select-table-row-checkbox-js" | ||
type="checkbox" | ||
title="@i18n('selectableTable.row.selection')" | ||
data-entity-id="@entityId"/> | ||
</td> | ||
<i:render name="body"/> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters