Deleting table row(s)
- Import delete confirm modal
{{ template "delete-confirm-modal" . }}
to the page with the table. Modal can be custom, but there is few requirements that should be implemented: Modal confirm button must submit the form with method POST. Submitted form should include inputs:<input type="hidden" name="postAction" value="delete">
, value delete may be set dynamically using JS, or statically like in sample if related form used only for the delete action<input type="hidden" name="postActionEntity" value="ModelDtoList">
, where value is the entity name which table is related to. Usually ends withList
<input type="hidden" name="postActionIds" value="1,2,3">
, where value is the ids of each entity separated by comma. If only one id, then just a number, like value=“1”
- There is also a default delete confirmation modal that can be used during custom template creation. Use the statement from option 1 to import it. Here is a sample how to use it:
<!-- GET may be used for search, after delete confirmation it would be changed to POST -->
<form method="get" id="entity-table-id">
<input type="hidden" name="postAction" id="table-action">
<input type="hidden" name="postActionIds" id="table-selected-rows" value="{{ .Data.Parameters.postActionIds }}">
<input type="hidden" name="postActionEntity" id="table-entity">
<button data-form-id="entity-table-id"
data-delete-identifier="{{ .ID }}"
data-post-action-entity="DeviceList"
class="table-action-button action-row-red form-delete-button">
<i class="material-icons material-icons-outlined">delete_forever</i>
</button>
</form>
Note
Ids and names for inputs should be the same as in sample. Values are optional. The button should have data-form-id set to the related form id, data-post-action-entity should have the name of the entity that is related to the table. Button should have class form-delete-button.