From what I understand, you have two questions:
-
How to put checkboxes on your CRUD list in order to delete all items at once.
It seems that you are using
update_list()
to load all items on your table. Since thats the case, you need to add an extra<td>
in that row to that iteration with the checkbox element.data.results.forEach(function (i) { $("#list").find("tbody").append( "<tr>" + "<td><input class="item_checkbox" type="checkbox"/></td>" + "<td>" + i.pais + "</td>" + "<td>" + i.nome + "</td>" + "<td>" + i.empresa + "</td>" + "<td align='center'><a class="btn btn-primary glyphicon glyphicon-pencil" title="Editar" id='edit_link' href="" + JSON.stringify(i) + ""></a> | <a class="btn btn-danger glyphicon glyphicon-trash" title="Deletar" id='delete_link' href="" + JSON.stringify(i) + ""></a></td>" + "</tr>" ); });
Once you have that set, you can then use jquery to collect all checkboxes by class
.item_checkbox
and run a delete function. -
How to make sure the SELECT country field is pre-selected when you EDIT an item
Since you are using bootstrap modals, when you edit an item, that modal will popup showing that info. What you need to do is send that item’s country ID to that modal’s form so that it can be preselected, so do the following change:
first in
#editar_modal
<div class="form-group"> <label class="control-label">PaĆs:</label> <select id="pais_input" name="pais"> <?php foreach ($array_pais as $pais) { ?> <option value="<?php echo $pais ?>"><?php echo $pais ?></option> <?php } ?> </div>
then in
'#edit_link', 'click', function (e)
add:$modal.find("#pais_input").val(info.pais);
6
solved Delete selected Items with modal confirmation PHP