我正在使用jquery-datatables-editable并尝试设置更新时发布的值 根据文档,这可以通过设置sName属性(属于aoColumns)来完成 我已经尝试过这些示例,两者都在aoColumns和aoColumnDefs中定义,没有运气。
任何想法?
代码示例;
在视图中:
<?php
<div>
<button id="p_btnAddNewRow">Add</button>
<button id="p_btnDeleteRow">Delete</button>
<div id="p-container">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="p-table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php
if (isset($p['primary']) && is_array($p['primary']) && (count($p['primary']) > 0)) {
foreach ($p['primary'] as $primary) {
?>
<tr id="<?php echo $primary->id; ?>">
<td><?php echo $primary->code; ?></td>
<td><?php echo $primary->name; ?></td>
<td><?php echo $primary->notes; ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
?>
JS;
<script type="text/javascript">
var pTable;
$(function() {
pTable = $('#primary-audiences-table').dataTable().makeEditable({
sAddNewRowFormId: "p_formAddNewRow",
sAddNewRowButtonId: "p_btnAddNewRow",
sAddURL: "/templates/ptable/add",
fnOnNewRowPosted: function(data) {
if(data.indexOf("Error", 0) == 0) {
//Show error message
return false;
} else {
//Show success message and add row
return true;
}
},
sUpdateURL: "/templates/ptable/edit",
sDeleteRowButtonId: "p_btnDeleteRow",
sDeleteURL: "/templates/ptable/delete",
"aoColumns": [
{
sName: 'code',
indicator: 'Saving ID...',
tooltip: 'Double Click to edit',
type: 'textarea',
submit: 'Save changes'
},
{
sName: 'name',
indicator: 'Saving name...',
tooltip: 'Double Click to edit',
type: 'textarea',
submit: 'Save changes'
},
{
sName: 'notes',
indicator: 'Saving notes...',
tooltip: 'Double Click to edit',
type: 'textarea',
submit: 'Save changes'
}
]
});
});
示例回复($ _POST的print_r):
(
[value] => test
[id] => 2784
[rowId] => 0
[columnPosition] => 0
[columnId] => 0
[columnName] => ID <- should be **code**
)
答案 0 :(得分:0)
我找到了答案:给程序员更多咖啡(那就是我)并正确阅读文档!!
sName 属性与 dataTables 扩展名相关联,不 makeEditable 扩展名。文档中的示例确实显示了这一点,但我没有正确阅读;我的坏。
因此,正确的写作方式是;
<script type="text/javascript">
var pTable;
$(function() {
pTable = $('#primary-audiences-table').dataTable({
aoColumns: [ {"sName": "code"}, {"sName": "name"}, {"sName": "notes"} ]
}).makeEditable({
sAddNewRowFormId: "p_formAddNewRow",
sAddNewRowButtonId: "p_btnAddNewRow",
sAddURL: "/templates/ptable/add",
fnOnNewRowPosted: function(data) {
if(data.indexOf("Error", 0) == 0) {
//Show error message
return false;
} else {
//Show success message and add row
return true;
}
},
sUpdateURL: "/templates/ptable/edit",
sDeleteRowButtonId: "p_btnDeleteRow",
sDeleteURL: "/templates/ptable/delete",
"aoColumns": [
{
indicator: 'Saving ID...',
tooltip: 'Double Click to edit',
type: 'textarea',
submit: 'Save changes'
},
{
indicator: 'Saving name...',
tooltip: 'Double Click to edit',
type: 'textarea',
submit: 'Save changes'
},
{
indicator: 'Saving notes...',
tooltip: 'Double Click to edit',
type: 'textarea',
submit: 'Save changes'
}
]
});
});
</script>