How to get POST fields without the actual POST?

How to get POST fields without the actual POST?

DaveBurnsDaveBurns Posts: 17Questions: 0Answers: 0
edited December 2011 in General
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?

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Have a look at the download plug-in for TableTools: http://datatables.net/extras/tabletools/plug-ins - it called the internal DataTables method _fnAjaxParameters which is what I think you want in this case. You can then post those parameters to the server.

    Allan
  • DaveBurnsDaveBurns Posts: 17Questions: 0Answers: 0
    Thanks, Allan. I can't tell if you're suggesting I use TableTools and that plugin or calling that internal API directly. Do you suggest I avoid calling _fnAjaxParameters directly since it's internal?
  • DaveBurnsDaveBurns Posts: 17Questions: 0Answers: 0
    Allan - Trying the internal API route and having an issue. I see this line in the code for the download plug-in:
    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.
  • DaveBurnsDaveBurns Posts: 17Questions: 0Answers: 0
    This worked for me:
    var oParams = report.oApi._fnAjaxParameters( report.fnSettings() );
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Yup sorry - I should have made myself a bit clearer! However, you've arrived at exactly the solution I was thinking of :-) Nice one.

    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
This discussion has been closed.