I'm using datatables with pagination and within each row I have
edit function that I load via modal popup.
If I change the page, dom got lost and so I can't open the edit function as modal popup anymore.
The problem:
https://datatables.net/faqs/#events
The solution
https://datatables.net/examples/advanced_init/events_live.html
I read both but I still can't figure out how to make it work with my Edit link.
On click link with class dlgTrigger the popup opens. Easy thing but not with this datatables combination and without further knowledge of js.
Hope someone can help me to understand how to define the link within this datatable js.
That's how my table looks like (short form to give an example):
<script>
$(document).ready(function() {
$('#syslog').DataTable({
order: [[ 0, "desc" ]],
pageLength: 10,
"lengthMenu": [ [10, 30, 60, 120, -1], [10, 30, 60, 120, "All"] ]
});
});
</script>
Table
<table id="syslog">
<thead><tr><td>Report</td><td>Actions</td></tr></thead>
<tr><td>text123</td>
<td><a href="edit/report.php?id=123" class="dlgTrigger" title="Edit"><li class="fa fa-edit"> </li></a></td></tr>
<tr><td>text456</td>
<td><a href="edit/report.php?id=456" class="dlgTrigger" title="Edit"><li class="fa fa-edit"> </li></a></td></tr>
</table>
Dialog
<script>
$(document).ready(function() {
$('A.dlgTrigger').click(function(event) {
event.preventDefault();
dlg = $('<div></div>').append(loading.clone());
dlg
.load($(this).attr('href'), function(response, status, xhr) {
if ( status=="error" ) {
alert("Dialog definition not available ("+xhr.status+" "+xhr.statusText+")");
//dlg.dialog("close");
}
})
.dialog({
title: $(this).attr('title'),
width: 300,
height: 300,
modal: true,
resizable: false,
close: function() {
dlg.empty();
}
});
});});
// ]]></script>
question from:
https://stackoverflow.com/questions/65872918/how-to-add-modal-popup-to-datatables 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…