How to add click event listener for every newly added table row?

When the Detail Edit page is loaded, I can use .addEventListener() to add a click event listener to every existing row in a table using a for loop with the length of the table.

But how about the newly added row that is added to the table during the program processing?

I want every row of the table regardless of whether it is an existing row or a new row to have the click event handler.

What is the best way to accomplish this so that all rows are able to respond to the click event?

Hi annaylee,

 

A way to deal with this would be to delete all the events in each row of the table when you open the record edit screen and then resubmit them.

Could you check and see by deleting and resubmitting an event within a registered event that helps you resolve the issue?

 

※Deleting events for the rows I added, but no errors occurred.

 

(function() {

"use strict";

var setfunction = function(event){

alert("click");

for(var n=1; n < document.getElementsByClassName('subtable-gaia')[0].rows.length; n++){

document.getElementsByClassName('subtable-gaia')[0].rows[n].removeEventListener('click', setfunction);

}

for(var m=1; m < document.getElementsByClassName('subtable-gaia')[0].rows.length; m++){

document.getElementsByClassName('subtable-gaia')[0].rows[m].addEventListener('click', setfunction);

}

}

kintone.events.on("app.record.edit.show", function(event) {

for(var i=1; i < document.getElementsByClassName('subtable-gaia')[0].rows.length; i++){

document.getElementsByClassName('subtable-gaia')[0].rows[i].addEventListener('click', setfunction);

}

});

})();

 

Hopefully, this helps.