lbr*_*him 3 jquery datatables inline-editing
我一直在尝试在jQuery Datatable中实现简单的内联编辑.但我无法激活点击行单元格时发生的编辑.我使用与其网站链接相同的代码:
<table id="Datatable" cellpadding="0" cellspacing="0" border="0" class="display">
<thead>
<tr>
<th>Age</th>
<th>Name</th>
</tr>
</thead>
</table>
Run Code Online (Sandbox Code Playgroud)
数据绑定:
/* 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%"
});
Run Code Online (Sandbox Code Playgroud)
任何建议都非常感谢.
Ell*_*ott 15
我构建了一个插件,它将在大约两行代码中为您完成此操作.它虽小但非常基本,但可以完成工作.回购邮件在这里:DataTables CellEdit插件
基本初始化快速简便:
oTable.MakeCellsEditable({
"onUpdate": myCallbackFunction
});
myCallbackFunction = function (updatedCell, updatedRow) {
console.log("The new value for the cell is: " + updatedCell.data());
}
Run Code Online (Sandbox Code Playgroud)
更新:这在过去几个月里逐渐增长,并且比我第一次发布这个答案时有更多的功能.感谢所有的贡献者在那里投球!