Submitting forms with pagination

Submitting forms with pagination

TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
edited May 2013 in DataTables 1.9
Hi,

I know the examples for sending forms with serialize(), e.g. described on this page:
http://www.datatables.net/examples/api/form.html

But I am not able to send all elements in a form. My code looks like this:

[code]$('#myform').submit( function() {
var sData = $(':checkbox', oTable.fnGetNodes()).serialize();
alert( "The following data would have been submitted to the server: \n\n"+sData );
return true;
}); [/code]

But I only see the first two selected checkboxes in my GET string:
[quote]file:///home/andi/downloads/DataTables-1.9.4/DataTables-1.9.4/untitled.html?example_length=10&lala=on&lala3=on[/quote]
The value "lala2=on" is missing in my case.

Do I need to submit the values myself somehow? The alert box shows all entries, only the GET string is missing everything that is not on the first pagination page.

Thanks for your help, I'm new to Javascript and jQuery, so maybe this is a stupid question for some of you :-)

Andi

Replies

  • allanallan Posts: 63,107Questions: 1Answers: 10,394 Site admin
    We'd need a test case to understand why it isn't working.

    Allan
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    Hi,

    I test my javascript "select all" method with the following html table:
    http://pastebin.com/dcjqvWUx

    The goal of the "select all" function is to select all data rows if no filter is selected, otherwise select the filtered rows. This works well, but now I need to submit the form and only the values in the first page are sent.

    I test it as follows: Press "All", then "Submit". The dialog box displays all variables, but the GET parameters in the browser show only the parameters from the first page.
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    When I click on "Select All", then "Last" in the pagination section and then "Submit", it adds the values from the last page...
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    I guess I just need to submit the content of the variable "sData"... but how? I'll try the jQuery documentation again...
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    Hmm I guess I need to find out if the action is GET or POST and than call jQuery.get() or jQuery.post()...
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    edited May 2013
    Hmm jQuery.get("", sData) doesn't seem to work...
  • allanallan Posts: 63,107Questions: 1Answers: 10,394 Site admin
    Are you saying that `sData` contains what you need? In which case, yes, you would just submit that using standard jQuery methods like $.ajax .

    Allan
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    yes, sData contains all the data (the checked checkboxes). But somehow sending with jQuery.get, $.get or $.ajax doesn't work for me. It seems the data is not send.
    Example:
    http://pastebin.com/uqE6MQif

    The page isn't refreshed as well, so I guess the GET request isn't send. Even if I change the url in $.ajax to a different website (e.g. google.com), the browser doesn't show the page the data is sent to (normally I would see the google website now?).

    Andi
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    The only way I get it to work is by calling

    [code]oTable.fnDestroy();
    return true;[/code]

    in the submit callback handler. But this doesn't look good because the table is displayed as a normal HTML table again, before the POST is actually redirected to the new page.
  • allanallan Posts: 63,107Questions: 1Answers: 10,394 Site admin
    Using `$.ajax( string, string )` doesn't appear to be a supported call from the jQuery documentation: http://api.jquery.com/jQuery.ajax/ .

    I'd suggest making a valid $.ajax - probably using an object with the properties set, as shown in the jQuery document and seeing if that helps.

    Allan
  • TheGrudgeTheGrudge Posts: 9Questions: 0Answers: 0
    I tried all the different methods, including $.ajax() with this code:
    [code]
    var request = $.ajax({
    url: "",
    type: "GET",
    data: sData
    });
    return false;
    [/code]
    It doesn't work, the page isn't refreshed and therefore the application where we use datatables is not able to call the appropriate action. The "request" object is created and no error is thrown. The only way it seems to work is by destroying the datatable in the submit callback.
This discussion has been closed.