I am using jquery-datatables-editable and am trying to set the value that gets posted on update.
According to the documentation this can be done by setting the sName property(which belongs to aoColumns).
I have tried following the examples, both defining in aoColumns and aoColumnDefs with no luck.
Any ideas?
Code samples;
In view:
<?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'
}
]
});
});
Sample response (print_r of $_POST):
(
[value] => test
[id] => 2784
[rowId] => 0
[columnPosition] => 0
[columnId] => 0
[columnName] => ID <- should be **code**
)
I have found the answer: give the programmer more coffee (thats me) and read the documentation properly!!
The sName property is associated to the dataTables extension, NOT the makeEditable extension. The example in the documents does show this but I failed to read properly; my bad.
Therefore the correct way to write it is;