form.serialize only retrieves values of current page

form.serialize only retrieves values of current page

PieterBPieterB Posts: 2Questions: 0Answers: 0
edited November 2013 in General
Currently I have this code to get my values from the datatable:

[code]
$(this).on('click', '#AddSelectedProjectCandidateReportRecipientsSubmitButton', function (e) {
e.preventDefault();
var form = $('#AddProjectCandidateReportRecipientsForm');
ShowDetailSaveDialog();
$.ajax({
url: form.attr('action') + '/' + form.attr('data-project-candidate-id'),
type: 'POST',
data: form.serialize(),
success: function (data) {
HideDetailSaveDialog();
$('#AddProjectCandidateReportRecipientsDialog').dialog('close');
RefreshProjectCandidateReportRecipients(form.attr('data-project-candidate-id'));
return false;
},
error: function (x, y, z) {
alert(x.responseText);
}
});
});
[/code]

It only gives me the values of the current page

I already tried a milion ways to try get all data from the datatable with fnGetData / fnGetNodes /... but when I attempt to retrieve my datatable I think he's not finding it. I tried with $(table).dataTable, $("#myform").dataTable and some more but nothing works.

Anyone has a solution for me?

Thanks in advance.

Replies

  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    Please see this example: http://datatables.net/release-datatables/examples/api/form.html

    Allan
  • PieterBPieterB Posts: 2Questions: 0Answers: 0
    edited November 2013
    Hi Allan,

    Thanks for replying, I already tried this before and the sData was empty...

    [code]
    $(this).on('click', '#AddSelectedProjectCandidateReportRecipientsSubmitButton', function (e) {
    e.preventDefault();
    oTable = $(table).dataTable();
    var sData = oTable.serialize();
    var form = $('#AddProjectCandidateReportRecipientsForm');
    ShowDetailSaveDialog();
    $.ajax({
    url: form.attr('action') + '/' + form.attr('data-project-candidate-id'),
    type: 'POST',
    data: sData,
    success: function (data) {
    HideDetailSaveDialog();
    $('#AddProjectCandidateReportRecipientsDialog').dialog('close');
    RefreshProjectCandidateReportRecipients(form.attr('data-project-candidate-id'));
    return false;
    },
    error: function (x, y, z) {
    alert(x.responseText);
    }
    });
    });
    [/code]

    Is there something wrong with this code?
  • allanallan Posts: 63,383Questions: 1Answers: 10,449 Site admin
    yes, you are only serialising the data on the first page. Try replacing:

    > $(table).dataTable();

    with:

    [code]
    $(table).dataTable().$('tr');
    [/code]

    Allan
This discussion has been closed.