getting the object id into the jeditable put

getting the object id into the jeditable put

darthghandidarthghandi Posts: 2Questions: 0Answers: 0
edited August 2012 in General
Hi, and thanks for datatables!
I would like to send a HTTP PUT with jeditable using the id in the table row. For example:
[code]
var tabledata = [["1234", "The name", "true"], ["12345", "Another name", "false"]];
var foo = $("#bar").dataTable({
aaData: tabledata,
aoColumns: [
{"sTitle": "id", "bVisible": false},
{"sTitle": "Name", sWidth: "65%"},
{"sTitle": "Default", sWidth: "35%"}],
bJQueryUI: true,
bAutoWidth: false,
bDeferRender: true,
bPaginate: false
});
[/code]

And the jeditable:
[code]
foo.$('td').editable("/api/something/" + idFromTheNameIAmEditing,
method : 'PUT',
data : function() {
var jsonString = '{"id": "idFromTheNameIAmEditing", "name": "editedName"}';
return jsonString;
} , {
"callback": function( sValue, y ) {
var aPos = foo.fnGetPosition( this );
foo.fnUpdate( sValue, aPos[0], aPos[1] );
},
"submitdata": function ( value, settings ) {
return {
"row_id": this.parentNode.getAttribute('id'),
"column": releaseList.fnGetPosition( this )[2]
};
}
});
[/code]

That way when I edit the name in the table, I can get the id and use that to send a JSON object to the rest api.
Does that make sense? Is there a way to do this?
Thanks for your time.

Replies

  • darthghandidarthghandi Posts: 2Questions: 0Answers: 0
    edited August 2012
    So I figured something out. With jeditble, you can specify a function instead of a url, so I did this:
    [code]
    foo.$('td:eq(0)').editable(function(value, settings) {
    var objectId = foo.fnGetData(releaseList.fnGetPosition(this)[0], 0);
    $.ajax({
    //I'm doing an http put since the app needs that for my situation
    type: "PUT",
    url: "api/foo/" + ojectId,
    dataType: "json",
    contentType: "application/json",
    //This is the data I'm sending in the put
    data: '{"name": "' + value + '"}'
    });
    return value;
    },{
    //I want to edit on a double click
    event: "dblclick",
    callback: function( value, settings) {
    var aPos = foo.fnGetPosition( this );
    foo.fnUpdate( value, aPos[0], aPos[1] );
    }
    });
    [/code]
This discussion has been closed.