Datatables update and save single cell on click

Datatables update and save single cell on click

noslannoslan Posts: 29Questions: 0Answers: 0
edited January 2014 in Editor
I'm able to update, using fnupdate, a single cell on click using this code:
[code]
$(document).ready(function() {
$('#example').on( 'click', 'td:nth-child(12)', function () {
oTable = $('#example').dataTable();
var aPos = oTable.fnGetPosition( this );
alert(aPos);
oTable.fnUpdate( 'new data', aPos[0], aPos[1] );
} );
} );
[/code]
What I need is to save this new change or toggle in db, but its not working with the above code, is there any way to reach it?

Replies

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Are you using Editor? If so, you need to use the `edit()` API method: https://editor.datatables.net/api/#edit . Using the API you can automatically create the edit, set the values and then submit the form for saving to the database.

    Allan
  • noslannoslan Posts: 29Questions: 0Answers: 0
    yes I'm using editor, I'm gona check it right now, Thanks!
  • noslannoslan Posts: 29Questions: 0Answers: 0
    So, I'm interested in "// Automatically submit an edit without showing the user the form"
    [code]
    editor.edit( TRnode, null, null, false );
    editor.set( 'name', 'Updated name' );
    editor.set( 'access', 'Read only' );
    editor.submit();[/code]

    TRnode should be "this"?
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Your event handler is on the `td` element, while the `edit()` method expects a `tr` element as the first parameter. So `this.parentNode` will do it in the above case.

    Allan
  • noslannoslan Posts: 29Questions: 0Answers: 0
    Thanks Allan, working as expected!
This discussion has been closed.