【问题标题】:JQuery .on('click') is not working with KTDatatable each row edit dropdown menuJQuery .on('click') 不适用于 KTDatatable 每行编辑下拉菜单
【发布时间】:2019-07-28 04:39:13
【问题描述】:
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, 

我的代码如下 //数据表代码 var KTDatatableRecordSelectionDemo = function() { //..... //..... 列: [{ }, //..... { 字段:'动作', 标题:'动作', 模板:函数(行){ return '\\\\\\ 组织详细信息\class="dropdown-item" href="#">位置和联系方式\税务设置和银行详细信息\访问权限\class="dropdown-item" href="#" id="one_another"> 个人资料图片和打印徽标\\\';},}]

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

            }
        }

【问题讨论】:

    标签: javascript twitter-bootstrap metronic


    【解决方案1】:

    你不能直接使用onClick,因为表格没有初始化,而是使用类似的东西在表格加载后添加点击事件。

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

    在表格本身中使用类似这样的东西在表格行中添加按钮

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

    【讨论】:

      【解决方案2】:

      尝试从 build.json 配置资产中删除 dompurify。此插件可清理数据表自定义 HTML 模板选项。

      【讨论】:

        猜你喜欢
        • 2023-03-10
        • 1970-01-01
        • 2014-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        相关资源
        最近更新 更多