how to close the previous opened tr from td.dt-control
how to close the previous opened tr from td.dt-control
javascript:
table.on('click', 'td.dt-control', function (e) {
let tr = e.target.closest('tr');
let row = table.row(tr);
if (row.child.isShown()) { row.child.hide(); }
else {
// Open this row
row.child(format(row.data())).show();
// validate for contact docs - if uploaded change icon color
$.ajax({
type: "POST",
url: "inc/db.cfmw.php?checkContactDocs",
data: {
contactID: row.data().id
},
success: function(response) {
// check for docs are available
if (response) {
$('#contactDocs').html('<img src =' + appURL + 'images/file-earmark-check.svg id="contactDocsIcon" onclick="contactDocsIcon(' + row.data().id + ')" alt = "" width = "20" height = "20">');
}
}
});
}
});
Description of problem:
hi team,
as the standard of .closest is up the dom i can't figure out on how to make sure that whenever a user is opening up a new row the previous opened one (s) is closed... just to make sure that closest is always the selected row...
with the standard i can start from the bottom up and my code is adding the document icon to the correct row. if i start from the top the adding is always one row short...
please help, as i am fiddling around already the whole afternoon (4 hours) and can't get it fix.
if my explanation is not making sense to you: i would love to have closed all tr's other than the selected (clicked one)
cheers & thank you so much for your help, tips, pointing me to the right direction...
This question has an accepted answers - jump to answer
Answers
Hi,
Inside your
click
event handler, check to see if there are anytr
rows which have thedt-hasChild
class - they are "open":Then go on to do the rest of your open / close interaction code.
Allan
works like a charme!!!!! i owe you a glass of milk!!!!!! thank you so much!
Awesome - good to hear .
Allan