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

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
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
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.
Returning the columns in this format (
columns[0][data]=name
) is the documented behavior of server side processing. One option might be to useajax.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
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!