简体   繁体   中英

JQuery .on('click') is not working with KTDatatable each row edit dropdown menu

Hi I am facing some issue with KTDatatable dropdown edit for each row, datatable.on(‘click’, is not picking my click event, please help.
The click event is from bootstrap dropdown, 

My code is as follows //Datatable code var KTDatatableRecordSelectionDemo = function() { //..... //..... columns: [{ }, //..... { field: 'Actions', title: 'Actions', template: function(row) { return '\\\\\\\\\\\\ Organization Details\\class="dropdown-item" href="#"> Location and contact detials\\ Tax settings and bank details\\ Access rights\\class="dropdown-item" href="#" id="one_another"> Profile image and print logo\\\\\\';},}]

        and here below the init datatable function



        var localSelectorDemo = function() {
        var datatable = $('#organizations').KTDatatable(options);
        //....
        //....
        datatable.on('click', '#form_organisation_details', function() {
            var dataId = $(this).attr("data-id");
            console.log(dataId);
        }

            }
        }

you can't use onClick directly because the table was not initialized instead use something like this to add the click event after the table is loaded.

$(table_id).on('click', '.btn-edit', function(e){
        e.preventDefault();
            $.ajax({
                type: 'get',
                url: 'some link here',
                success: function (data) {
                    $("#response").html(data);
                },
            });
    });

and in the table itself use something like this to add the button in the table row

return Datatables::of($data)->addColumn('actions',function($row){
                return '<a title="Edit" class="btn-edit"><i class="la la-edit"></i></a>';
            })->rawColumns(['actions'])->make(true);

Try to remove dompurify from the build.json config assets. This plugin sanitizes the datatable custom HTML template option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM