How to get POST fields without the actual POST?
How to get POST fields without the actual POST?
I'm using server-side processing and it all works fine. I want to add a link on the same page that will generate a CSV file. TableTools won't work here because I want the CSV to contain all filtered rows, not just those visible on the client. When that link is clicked, I need to POST to my CSV generator on the server all of the usual values (search, sort, etc.) that DataTables posts so that the CSV can recreate the filter that the user sees. How can I get these values?
I've tried fnSettings but that doesn't get the right set of data.
I'm already using fnServerData for other reasons. I wonder about a hack where I set a flag in my link's click handler, invoke fnDraw, then POST to a different URL when I'm in fnServerData and I see the flag. This seems a bit roundabout for a simple problem: isn't there a way to ask DataTables, "what *would* you POST" ? DataTables must be doing this since it's creating the data structure I'm looking for before calling fnServerParams and fnServerData. Or am I approaching this the wrong way?
I've tried fnSettings but that doesn't get the right set of data.
I'm already using fnServerData for other reasons. I wonder about a hack where I set a flag in my link's click handler, invoke fnDraw, then POST to a different URL when I'm in fnServerData and I see the flag. This seems a bit roundabout for a simple problem: isn't there a way to ask DataTables, "what *would* you POST" ? DataTables must be doing this since it's creating the data structure I'm looking for before calling fnServerParams and fnServerData. Or am I approaching this the wrong way?
This discussion has been closed.
Replies
Allan
var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
In my own code, I have this line early on:
report = $( '#reportTable' ).dataTable()
And then in my click() handler for my link, I use this line:
var oParams = report.oApi._fnAjaxParameters( report );
But that bombs one level down in the call stack with an error:
a.aoColumns is undefined
What is the proper parameter to pass to _fnAjaxParameters?
Thanks.
var oParams = report.oApi._fnAjaxParameters( report.fnSettings() );
The one thing to be aware of is that you are using an internal function, and there is the slightly possibility that it will change in future releases. Unlikely I would say until something like 2.0 (certainly it isn't changing in 1.9) but something to be aware of :-)
Allan