Server side + editable column

Server side + editable column

badeabadea Posts: 16Questions: 0Answers: 0
edited April 2011 in General
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.
?

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Does editable_ajax.php save the data to your database? The demo script doesn't (since I've no idea in advance what database schema is going to be used :-) ). You need to modify it to save the data submitted permanently.

    Allan
  • badeabadea Posts: 16Questions: 0Answers: 0
    edited April 2011
    Hi 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.
  • badeabadea Posts: 16Questions: 0Answers: 0
    I have to add some code at initialisation ?
  • badeabadea Posts: 16Questions: 0Answers: 0
    edited April 2011
    Hi to all!

    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.
  • ekooekoo Posts: 3Questions: 0Answers: 0
    edited September 2011
    (edit: I went further down the rabbit hole and found some more discussions on this, and will be working through the recommendations)

    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.
This discussion has been closed.