jQuery DataTable内联编辑 [英] jQuery DataTable Inline Editing

查看:280
本文介绍了jQuery DataTable内联编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在jQuery Datatable中实现简单的内联编辑。但是我无法激活单击行单元格时发生的编辑。我在他们的网站链接

I have been trying to implement simple Inline editing in jQuery Datatable. But I cannot activate the edit that happens on click on a row cell. I used the same code as in their site Link:

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

任何建议都值得赞赏。

推荐答案

我构建了一个插件,它将用大约两行代码为您完成此操作。它很小,很基础,但是可以完成工作。仓库在这里: DataTables CellEdit插件

I built a plugin that'll do this for you in about two lines of code. It's small and pretty basic but gets the job done. The repo is here: DataTables CellEdit Plugin

基本的初始化过程非常简单快捷:

The basic initialization is quick and easy:

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

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

更新:在过去的几个月中,它比我最初发布此答案时具有更多功能。感谢所有的贡献者!

Update: This has slowly been growing over the past few months and has quite a few more features than when I first posted this answer. Thanks to all the contributors out there pitching in!

这篇关于jQuery DataTable内联编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆