最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin7浏览0评论
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);
        }

            }
        }
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);
        }

            }
        }
Share Improve this question edited Jul 29, 2019 at 8:57 user3387166 asked Jul 28, 2019 at 4:39 user3387166user3387166 311 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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.

发布评论

评论列表(0)

  1. 暂无评论