I have generated a table from custom settings data, and I want the user to select a table row to edit the settings data.
This generates the table from custom settings:
var tableRef = document.getElementById("customTagTable").id;
for (i = 0; i < Object.keys(customMenus).length; i++) {
let row = customTagList.insertRow();
let rowId = customMenus[i].menuId;
row.setAttribute('id', rowId);
var addCell = row.insertCell(0);
var newText = document.createTextNode(customMenus[i].menuArg)
addCell.appendChild(newText);
var addCell = row.insertCell(0);
var newText = document.createTextNode(customMenus[i].parentId)
addCell.appendChild(newText);
var addCell = row.insertCell(0);
var newText = document.createTextNode(customMenus[i].menuTitle)
addCell.appendChild(newText);
var addCell = row.insertCell(0);
var newText = document.createTextNode(customMenus[i].menuId)
addCell.appendChild(newText);
And this hears the click, when the table body is clicked on:
customTagList.addEventListener("click", function(element) {
let rows = customTagList.getElementsByTagName('tr');
zzselection = customTagList.getSelectedItem;
console.log("moo", rows);
console.log(element.row);
console.log(zzselection);
});
The basic table format is:
<table id="customTagTable" border=2>
<thead id="customTableHead">
<tr>
<th>Menu ID</th>
<th>Menu Title</th>
<th>Parent ID</th>
<th>Menu Argument</th>
</tr>
</thead>
<tbody id="customTagList">
<tr>
</tbody>
</table>
I have been unable to programmatically get either the row id, or the index of the row without adding an onclick
to the <tr>
element, which throws a permission error.
I am under the impression that using onclick
in an extension is frowned upon, so how would I get the row id or index?