Datatables - fnGetNodes() how to push the results back to the server
Datatables - fnGetNodes() how to push the results back to the server
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
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
This discussion has been closed.
Replies
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
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?
[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]