Javascript 使用JSON数据表初始化X-Editable

Javascript 使用JSON数据表初始化X-Editable,javascript,php,json,ajax,Javascript,Php,Json,Ajax,我需要使用datatable初始化xeditable,但我无法使X-editable工作。我正在从另一个文件加载带有JSON数据的datatable。这是我的JavaScript function listCompJson(handleData) { var invType = $('#inv-type-select option:selected').val(); return $.ajax({ type: "POST",

我需要使用datatable初始化xeditable,但我无法使X-editable工作。我正在从另一个文件加载带有JSON数据的datatable。这是我的JavaScript

function listCompJson(handleData) {
        var invType = $('#inv-type-select option:selected').val();
        return $.ajax({
            type: "POST",
            dataType: 'json',
            url: "../_includes/inventory/process/process_inv_list.php",
            data: {invType: invType},
            success: function (json) {
                handleData(json);
            }
        });
    }

    //FEED JSON DATA TO DATATABLE
    function feedToTable() {
        listCompJson(function (response) {
            var initMinStock = 0;
            var table = $('#inventory-adjust-table').DataTable({
                processing: true,
                data: response,
                "columns":
                        [
                            {"data": "INV_DESC"},
                            {"data": "INV_UNIT"}
                        ],
                "columnDefs":
                        [
                            {
                                "visible": true,
                                "targets":[2],
                                "render": function (data, type,row, meta){
                                    var isi = '<a class="initStockClass" pk-data="'+row.INV_ID+'">'+row.STK_QTY+'</a>';
                                    return isi;
                                }
                            },
                            {
                                "visible": true,
                                "targets":[3],
                                "render": function (data, type,row, meta){
                                    var isi = '<a class="initMinStockClass" pk-data="'+row.INV_ID+'">'+row.MIN_STOCK+'</a>';
                                    return isi;
                                }
                            }
                        ]
            });
        });
    }

    function initEditable(){
        $('#inventory-adjust-table .initStockClass a').editable({
            type : 'text',
            title : 'enter stock'
        });
    }

    $(document).ready(function () {
        feedToTable();
        initEditable();
    });
函数listCompJson(handleData){ var invType=$('#inv type选择选项:selected').val(); 返回$.ajax({ 类型:“POST”, 数据类型:“json”, url:“../\u包括/inventory/process/process\u inv\u list.php”, 数据:{invType:invType}, 成功:函数(json){ handleData(json); } }); } //将JSON数据馈送到DATATABLE 函数feedToTable(){ listCompJson(函数(响应){ var initMinStock=0; 变量表=$(“#库存调整表”)。数据表({ 处理:对, 数据:答复, “栏目”: [ {“数据”:“INV_DESC”}, {“数据”:“库存单位”} ], “columnDefs”: [ { “可见”:真实, “目标”:[2], “呈现”:函数(数据、类型、行、元){ var isi=''+行标准单元数量+''; 返回isi; } }, { “可见”:真实, “目标”:[3], “呈现”:函数(数据、类型、行、元){ var isi=“”+行最小库存+“”; 返回isi; } } ] }); }); } 函数initEditable(){ $('#库存调整表.initStockClass a')。可编辑({ 键入:“文本”, 标题:“输入股票” }); } $(文档).ready(函数(){ 可饲料(); 初始化(); });
因此,当我点击列[2]时,我看不到xeditable弹出。请帮助我,我在这里做错了什么

您应该等待直到通过等待事件draw加载表。dt,dt是datatable的快捷方式,然后处理可编辑初始化:

$('#inventory-adjust-table').on( 'draw.dt', function () {
        $('#inventory-adjust-table .initStockClass a').editable({
                type : 'text',
                title : 'enter stock',
                success: function(response, newValue) {
                    console.log( response + " " + newValue);
                },
            }
        );
    } );

我也有同样的问题,它对我有用

var table= $('#inventory-adjust-table').DataTable();

table.on( 'draw', function () {
   $('#inventory-adjust-table .initStockClass a').editable({
                type : 'text',
                title : 'enter stock',
                success: function(response, newValue) {
                    console.log( response + " " + newValue);
                },
            }
        );
} );
数据表文档: