Datatables pagination buttons action not working (jQuery)

Preconditions (*)

  1. You are using Datatables & And for the Click event you are using  jQuery & you are using pagination

Steps to reproduce (*)

  1. Use a Datatables and on Action button you just use the class or id to make a click event to get row data on second or other pagination

    Javascript button event not work

Expected result (*)

  1. The click should work for the edit event

Actual result (*)

  1. The click trigger not working

Problem : 

jQuery('.editVendorAction').on('click', function (e) {
    let id = ($(this).attr("data-id"));

Solution :

we need to use event-delegation approach

jQuery('#dtVendor').on('click', '.editVendorAction', function (e) {
    let id = ($(this).attr("data-id"));

We use parent id in jQuery main selector

Was this article helpful?

Leave A Comment?

You must be logged in to post a comment.