Ok, I've been working on a small project for use with DataTables. Its a jQuery grid plugin and Ive got most the functionality working as intended now. The only thing I cant seem to wrap my head around is making the grid refresh on AJAX Inline edit.
<script type="text/javascript" charset="utf-8">
$(document).ready( function () {
var oTable = $('#example').dataTable({
"bJQueryUI": true,
"bProcessing": true,
"sAjaxSource": "/test/server_processing.php",
"sPaginationType": "full_numbers",
"aoColumns": [ { "bVisible": false },
null,
null,
null
]
}).makeEditable({
sAddURL: "AddData.php",
sAddHttpMethod: "GET",
sDeleteHttpMethod: "GET",
sDeleteURL: "DeleteData.php",
sUpdateURL: "UpdateData.php",
oAddNewRowButtonOptions: { label: "Add...",
icons: {primary:'ui-icon-plus'}
},
oDeleteRowButtonOptions: { label: "Remove",
icons: {primary:'ui-icon-trash'}
},
oAddNewRowFormOptions: {
title: 'New Toll Free number',
show: "blind",
hide: "explode",
modal: true
},
sAddDeleteToolbarSelector: ".dataTables_length"
});
} );
</script>
This is my updatedata.php file
$editedColumn = $_POST['columnId'];
$editedValue = $_POST['value'];
$id = $_POST['id'];
if ($editedColumn == '1') {
$sql = "update Main set name='$editedValue' where id='$id'";
} elseif ($editedColumn == '2') {
$sql = "update Main set dn='$editedValue' where id='$id'";
} elseif ($editedColumn == '3') {
$sql = "update Main set dn1='$editedValue' where id='$id'";
}
/* Update a record using information about id, columnName (property
of the object or column in the table) and value that should be
set */
$sql2 = "select name from Main where id = '$id';";
mysql_query($sql) or die(mysql_error());
echo "Update ok, reload to see changes";
I have the echo at the end because it seems to pop a alert() some where and the echo fills that alert with info.
I know of the functions for redrawing the grid like fnDraw but am clueless as how to implement.
If you need to reload the AJAX data of your Datatable based on an event or something, just use the fnReloadAjax
method. You can find the documentation here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With