4

我一直在尝试在 jQuery Datatable 中实现简单的内联编辑。但我无法激活单击行单元格时发生的编辑。我使用了与他们网站链接相同的代码:

<table id="Datatable" cellpadding="0" cellspacing="0" border="0" class="display">
    <thead>
        <tr>
            <th>Age</th>
            <th>Name</th>
        </tr>
    </thead>
</table>

数据表绑定:

    /* Init DataTables */
    var oTable = $('#Datatable').dataTable({
        "bProcessing": true,
        "sAjaxSource":"http://localhost:6220/DataSources/WCF/Data.svc/GetCustomer",
        "aoColumns": [
                            { "mDataProp": "Age" },
                            { "mDataProp": "Name" }
                     ]
    });

/* Apply the jEditable handlers to the table */              oTable.$('td').editable('http://localhost:6220/DataSources/WCF/Data.svc/SaveCustomer', {
                    tooltip: 'Click to edit...',
                    "callback": function (sValue, y) {
                        var aPos = oTable.fnGetPosition(this);
                        oTable.fnUpdate(sValue, aPos[0], aPos[1]);
                    },
                    "submitdata": function (value, settings) {
                        return {
                            "row_id": this.parentNode.getAttribute('id'),
                            "column": oTable.fnGetPosition(this)[2]
                        };
                    },
                "height": "14px",
                "width": "100%"
            });

任何建议都受到高度赞赏。

4

1 回答 1

19

我构建了一个插件,只需两行代码即可为您完成此操作。它很小而且很基本,但可以完成工作。仓库在这里:DataTables CellEdit Plugin

基本初始化快速简单:

oTable.MakeCellsEditable({
    "onUpdate": myCallbackFunction
});

myCallbackFunction = function (updatedCell, updatedRow) {
    console.log("The new value for the cell is: " + updatedCell.data());
}

更新:在过去的几个月里,这一直在缓慢增长,并且比我第一次发布这个答案时有更多的功能。感谢所有参与其中的贡献者!

于 2016-03-28T16:15:30.507 回答