Datatables - fnGetNodes() how to push the results back to the server

Datatables - fnGetNodes() how to push the results back to the server

rh0diumrh0dium Posts: 14Questions: 0Answers: 0
edited May 2012 in General
I've been struggling with with [datatables][1] and what to do with [code]fnGetNodes[/code] to correctly push the data back into the form on submit.

I've got the jquery working correctly. I can see the selected values as described in the [documentation][2]. My question is how do I take that `sData` and shove that back to the server in the POST??

I know it must be simple but I am clearly too focused on the tree to see the forest.. I'd appreciate any help on this!!

[code]


$(document).ready(function() {
$('#form').submit( function() {
var sData = $('input', oTable.fnGetNodes()).serialize();
alert( "The following data would have been submitted to the server: \n\n"+sData );
return false;
});

oTable = $('#data_table').dataTable();
});

[/code]


My HTML form looks like this (Shortened for clarity)

[code]



Select
Question


D1. Example of a multiple choice question
E1. Example of a multiple choice question
G. Example of a multiple choice question
H. Example of a multiple choice question
[/code]

[1]: http://datatables.net/
[2]: http://datatables.net/examples/api/form.html

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Two options:

    1. Use Ajax and set the data option for the request to be the serialised data.
    2. Inject hidden HTML input elements like in the example you linked to: http://datatables.net/examples/api/form.html

    Allan
  • rh0diumrh0dium Posts: 14Questions: 0Answers: 0
    Hey Allan,

    Thanks so much for replying - I think I need #2. When I submit I see this show up.

    [quote]
    questions=103&questions=104&questions=105&questions=106&questions=100&questions=101&questions=102
    [/quote]

    But when I look at the form data using the developer tools I can see the discrepency

    [quote]
    csrfmiddlewaretoken:a2c3ed6e1bfee9fce0b7412553aa2080
    name:Phase-1 Pre-Drywall
    priority:1
    description:Pre-Drywall inspection items
    use_for_confirmed_rating:on
    use_for_sampling:on
    data_table_length:10
    questions:103
    questions:104
    questions:105
    questions:106
    submit:Submit
    [/quote]

    So any ideas on transforming this?
  • rh0diumrh0dium Posts: 14Questions: 0Answers: 0
    It appears that I need to reset the questions and for each question append the selected ones back on.
  • rh0diumrh0dium Posts: 14Questions: 0Answers: 0
    edited May 2012
    And here it is. Pretty straightforward..

    [code]
    var oTable = $('#data_table').dataTable();
    // This will collect all of the nodes which were checked and make sure they get
    // pushed back.
    $('#form').submit(function () {
    $("input[name='question']").remove(); //Remove the old values
    $("input:checked", oTable.fnGetNodes()).each(function(){
    $('')
    .css("display", "none")
    .appendTo('#form');
    });
    });


    [/code]
This discussion has been closed.