Submit json when checkbox selected

Submit json when checkbox selected

jsmith3jsmith3 Posts: 19Questions: 4Answers: 0
edited March 2020 in Free community support

Hi all,
I'm using a setup similar to this https://editor.datatables.net/examples/api/checkbox.html
Where you select a checkbox, however instead of posting with the POST array data,
I wanted to modify $('#example').on('change', 'input.editor-active', function ( ) { }
So it submits json via XMLHttpRequest() the only issue i'm having is getting the related data
anyone know how to get the correct row index/data?

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    You can probably do something like this:

    var table = $('#example').DataTable();
    var row = $(this).closest('tr');
    var data = table.row( row ).data();
    

    The row-selector docs show the selectors you can use to select the row you want.

    Kevin

  • jsmith3jsmith3 Posts: 19Questions: 4Answers: 0

    Hi Kevin,

    I used this but got "undefined"

    var table = $('#example').DataTable();
    var row = $(this).closest('tr');
    var data = table.row( row ).data();

    alert( JSON.stringify(data) );

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    The code works in this example:
    http://live.datatables.net/guwafemu/41/edit

    Please update the example to show the problem you are having.

    Kevin

  • jsmith3jsmith3 Posts: 19Questions: 4Answers: 0

    OK I can confirm if the editor.edit line is left in and the code follows it, will produce an undefined but I commented mine out as well and it works thanks

  • jsmith3jsmith3 Posts: 19Questions: 4Answers: 0

    I have noticed the active checkbox value does not appear to update though, so when i send it via JSON.stringify() it always has a value of true

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    edited March 2020

    I can confirm if the editor.edit line is left in and the code follows it, will produce an undefined but I commented mine out as well and it works thanks

    Yes that happens. Thought you wanted to remove the POST that occurs in the example. You can use submitComplete to get the updated data values after the edit submit in the click event. For example:
    http://live.datatables.net/guwafemu/42/edit

    I have noticed the active checkbox value does not appear to update though, so when i send it via JSON.stringify() it always has a value of true

    We will need to see an example of this.

    Kevin

  • jsmith3jsmith3 Posts: 19Questions: 4Answers: 0
    edited March 2020

    Thanks Kevin, I've resolved it setting the data field manually,
    Very much appreciated.

This discussion has been closed.