How do I post column sort data in tabletools?

How do I post column sort data in tabletools?

crunchfactorycrunchfactory Posts: 29Questions: 8Answers: 2
edited June 2014 in DataTables 1.10

How do we post column sort data in tabletools, in this case, so we can mirror tablesorting in the table instance on our post of data to make into a csv, I thought it would be something like the bottom 2?

var oParams = this.s.dt.oApi._fnAjaxParameters( this.s.dt );
    var aoPost = [
        { "name": "action", "value": "csv" },
        { "name": "csvQuery", "value": table.ajax.params().search.value },
        { "name": "csvColumn", "value": table.ajax.params().order[i].column },
        { "name": "csvColDir", "value": table.ajax.params().order[i].dir }
    ];

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    I've just sent you a PM about this, but for anyone else reading, the problem with the above is the order[i] - in this case the i is undefined. You could replace it with 0 to get the first sorting column data, but it might be easiest to use JSON.stringify( table.ajax.params().order ) and then decode the array of objects as JSON at the server. Indeed, you could do JSON.stringify( table.ajax.params() ) and have everything from the last server-side processing request available at the server without needing to add each manually.

    Regards,
    Allan

  • crunchfactorycrunchfactory Posts: 29Questions: 8Answers: 2
    edited June 2014

    Beautiful, and thank you;

    JSON.stringify( table.ajax.params().order )

    I guess my surprise is that "table.ajax.params().order" was one of the first thing I tried, but it takes JSON.stringify to return the properties ans values?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    If you were to just use the order parameter, the client would simply be sending [object Object] to the server, as that is the toString() result of an array (since HTTP parameters are basically strings, the browser will get the string value of an object as the value to send). So you need to JSONify the object, or post the values individually.

    Regards,
    Allan

This discussion has been closed.