Submiting whole table to php

Submiting whole table to php

DzejCiDzejCi Posts: 3Questions: 2Answers: 0

Hi all,
I start using DataTables in my php project to show data from SQL table. The thing is that I need to send all the data from the whole table to my php script after pressing submit button, but it sends only "visible" data. For example - I have table that have 1k rows paginated "by 50". When I press Submit it sends only 50 rows of "visible" data instead of all of them.
I found related problem on this forum from 2015, it suggest to use var data = table.$('input, select').serialize(); but it does not work for me. Also, when I set it my browser starts to shows DataTables warning: table id=datatable - Cannot reinitialise alert.
What is in index:

$(document).ready(function() {
var table = $('#datatable').DataTable( {
paging: true,
displayStart: 0,
pageLength: 50
} );
$('button').click( function() {
var data = table.$('input, select').serialize();
window.location.replace("http://test.page.com/test.php?" + data);
return true;
});
});

How can I post data from whole table?

Answers

  • DzejCiDzejCi Posts: 3Questions: 2Answers: 0

    Even in the https://datatables.net/examples/api/form.html it is said that

    The $() method can be used to get nodes from the document regardless of paging, ordering etc

    but when you press submit button you will see that the alert contains only "visible" data.

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    That's not the case on the example you linked to. I change an input element on the last page of the table, went back to the first page, and typed this in the console:

    $('#example').DataTable().$('input').serialize()
    

    and all the input elements were returned as expected. Try the same on your page and see what happens there.

    Colin

Sign In or Register to comment.