Delegated events being lost after one of them actioned

Delegated events being lost after one of them actioned

tcardinaltcardinal Posts: 31Questions: 9Answers: 0

I have a datatable and each row has a series of links that do something (such as edit the name, archive the record). They are all linked with delegated calls"

 $("#folders").on("click", ".editfolder", function (event) {
            event.preventDefault();
            var table = $("#folders").DataTable();
            var row = table.row($(this).parents("tr"));
            smxTableDialogForm(this.href, "folders", row);
  });

folders is the table Id.

when the edit is complete the data in the table is updated and after the update is done the following is executed

$("#" + tableId).unbind("click");
var table = $("#" + tableId).DataTable();
setTimeout(function () { table.draw(); }, 1500);

However, after this all the events stop working.

I can give you a login to see this in action.

Answers

  • tcardinaltcardinal Posts: 31Questions: 9Answers: 0

    ok, I think I've spotted this one - wood and trees

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited March 2020

    You will probably want to use jQuery .off() to correspond with the on(). Maybe like this:
    $("#" + tableId).off("click", ".editfolder");

    Kevin

  • tcardinaltcardinal Posts: 31Questions: 9Answers: 0

    thanks Kevin. I have just removed the unbind. That is legacy code from when I was binding at a lower level I think, which is not needed now at the table level - time will tell :D

This discussion has been closed.