The dom_nodes
property return a type of read-only dict with all the anvil-names
you defined in your html.
So for your html that looks like this:
<table class="meal_ingredient_row_table">
<tbody>
<tr>
<!-- <td anvil-name="warning" style="width: 15%">
<img src="_/theme/material_icons/red_warning.svg" />
</td> -->
<td anvil-name="warning-column" style="width: 10%">
<button class="warning-button" anvil-name="warning-button">
<i class="material-symbols-outlined">warning</i>
</button>
</td>
<td anvil-name="quantity-column">column A</td>
<td anvil-name="food-column">column B</td>
<td anvil-name="edit-column" style="width: 15%"><a style="color: orange">edit</a></td>
<td anvil-name="delete-column" style="width: 15%"><a style="color: red;">delete</a></td>
</tr>
</tbody>
</table>
When you call self.dom_nodes
what you get is this:
mappingproxy({
'warning-column': <HTMLTableCellElement proxyobject>,
'warning-button': <HTMLButtonElement proxyobject>,
'quantity-column': <HTMLTableCellElement proxyobject>,
'food-column': <HTMLTableCellElement proxyobject>,
'edit-column': <HTMLTableCellElement proxyobject>,
'delete-column': <HTMLTableCellElement proxyobject>
})
If you try edit_column = self.dom_nodes['edit-column']
, the content of the edit_column
variable will be the js dom node for the TableCellElement, where you can add things on it, change the textContent, etc. However, this is js in python, not pure python. So to add this on it you will need to know how to handle javascript.
What I said about slots could apply here. If you change your html that has this:
<td anvil-name="edit-column" style="width: 15%"><a style="color: orange">edit</a></td>
To this:
<td anvil-name="edit-column" anvil-slot="edit-column" style="width: 15%"><a style="color: orange">edit</a></td>
Now you can add the IconButton
to the column. You can even add it programatically using
de = IconButton(align='center')
self.add_component(de, slot="edit-column")
You can also remove the text “edit” automatically when the slot has a text, but I don’t remember now how to do it. Let me know if this is what you expected.
Edit: again, you can achieve the same (and easier) just using a data table component from anvil, in this simple, toy problem.