Server side + editable column
Server side + editable column
Hi !
I need to get an editable column in "DataTable" (server side php+mysql)
According to this example http://datatables.net/examples/api/editable.html i added this code to my script:
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "view_prognosis.php",
"fnDrawCallback": function () {
$('#example tbody tr td:nth-child(9)').editable( 'editable_ajax.php', {
"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')};
},
"height": "14px"
} );
}
} );
} );
[/code]
The column appear to be editable, but the data isn't saved.
?
I need to get an editable column in "DataTable" (server side php+mysql)
According to this example http://datatables.net/examples/api/editable.html i added this code to my script:
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "view_prognosis.php",
"fnDrawCallback": function () {
$('#example tbody tr td:nth-child(9)').editable( 'editable_ajax.php', {
"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')};
},
"height": "14px"
} );
}
} );
} );
[/code]
The column appear to be editable, but the data isn't saved.
?
This discussion has been closed.
Replies
Allan
Thanks for reply.
I am beginner in ajax. So how to post data from ajax to php to make the update? I need to do an update like this:
[code]
mysql_query("UPDATE prognosis SET comment = '$value' WHERE id_prognosis = '$id'");
[/code]
So how to get the id of edited cell and the column name from ajax? Give me please an example.
Best regards.
Tired of searching the solution but finally I have found the answer.
So my initialization code is:
[code]
var oTable;
$(document).ready(function() {
oTable = $('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "server_processing.php",
"fnDrawCallback": function () {
$('#example tbody tr td:nth-child(9)').editable( 'editable_ajax.php', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
//alert(aPos[0]);
},
"submitdata": function ( value, settings ) {
return { "row_id": oTable.fnGetData( this.parentNode )[0], // get the value of first row/column. In my case it is the "id" in database
"column": oTable.fnGetPosition( this )[2] // Column number
};
},
"height": "10px"
} );
}
} );
} );
[/code]
and in editable_ajax.php get the values:
[code]
$_POST['value']; // value that was just edited
$_POST['row_id']; // row_id from (from the table) - see the comment in initialization code
[/code]
Hope that this will help the beginners.
P.S.
Allan I think that is needed a complete step by step example with jeditable for beginners.
Sorry to dig up an old thread, but I'm having the exact same problem. I'm guessing that it's something to do with my editable_ajax.php. Where does the actual "write" occur? I've got datatables working, the 3rd column is editable, but I'm just not able to figure out how to actually write my edit to mySQL.
Any help is appreciated. I'm simply looking to do a straight column update, php/mySQL.