AJAX Parameters - can you return column names vs. index?

AJAX Parameters - can you return column names vs. index?

jasper502jasper502 Posts: 25Questions: 9Answers: 0

Datatables sends requests like this:

locations.json?draw=2&columns[0][data]=name&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&order[0][column]=1&order[0][dir]=asc&start=0&length=15&search[value]=&search[regex]=false&q=&_=1578103827076

I have specified column names in my JS files and data attributes in my HTML. Can't Datatables return the proper labels i.e. name, description, etc. This way I can pars the parameters easy in my controllers.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Yep, it would send a data field which specified the column name, see example here.

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • jasper502jasper502 Posts: 25Questions: 9Answers: 0

    I am trying to build an example to post and will once I get is working properly. Having trouble with the source data as I don't have a live AJAX call to work with:

    http://live.datatables.net/carufuna/1/

    My code looks exactly like this already but my JSON requests still have the column[0] format etc.

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    Answer ✓

    Returning the columns in this format (columns[0][data]=name) is the documented behavior of server side processing. One option might be to use ajax.data as a function and encode the parameters as a JSON string, see the last example in the docs. Here is an example:
    http://live.datatables.net/wejijene/1/edit

    Kevin

  • jasper502jasper502 Posts: 25Questions: 9Answers: 0

    Thanks - confirmation that is the expected behaviour is enough. I can work with it but thought perhaps there was another way. I may try the data option also. Thanks!

This discussion has been closed.