Datatables Scripting and Form Submit
Datatables Scripting and Form Submit
Okay I am going a little bit crazy over this one so I thought maybe I could just ask a questions and someone who has used data-tables before could answer it.
First let me say great work on datatables it is a really nice package.
Okay now my problem
What I am trying to do is use data tables to hold form data so that the user can rapidly sort through the available options. Unfortunately it would appear that if the item is not displayed it is not submitted.
I need to submit all of the options so that I can loop through them and preform processing on the back end.
So I figured that the best way to go about it would be to attach an event to the submit button that would do display all values.
Here is my code.
var oTable;
...
oTable = oTable = $('#{$id}').DataTable( {...} );
...
function formSubmit() {
oTable.page.len(-1).draw();
}
That works fine as far as I can tell.
However the table has select box filters.
When you use one or more of the select filters and then submit the form it does not expose all of the data.
I figures the best thing to do would be to reset the form filters which I have tried using the following.
function formSubmit() {
oTable.fnFilterClear();
$("select").selectOptions("");
oTable.page.len(-1).draw();
}
For some reason it is not working and I am totally at a loss, I have tried many derivation and am missing something.
Any suggestions?
Answers
Okay so I think I have this solved.
Apparently I was very far off.
Based on this article I was doing a number of things wrong.
After doing some reading the code I was trying to use was from a plugin that I didn't include AND also depreciated with the latest release.
The correct code should be:
var oTable;
//...
oTable = DataTable(//...);
//...
function formSubmit() {
oTable.search( '' ).columns().search( '' ).draw();
oTable.page.len(-1).draw();
}
Here is the reference if you are searching for the same thing I was:
https://datatables.net/plug-ins/api/fnFilterClear