how to change format of output
how to change format of output
Hello, we know datatables send output with this format:
columns[0][data]= first_name
columns[0][name]=
columns[0][searchable]= true
columns[0][orderable]= true
columns[0][search][value]=
columns[0][search][regex]= false
but I need this format for output:
columns[0].data= first_name
columns[0].name=
columns[0].searchable= true
columns[0].orderable= true
columns[0].search.value=
columns[0].search.regex= false
How to can change format in datatables.net JQuery ?
Thanks
This question has accepted answers - jump to:
Answers
Use
ajax.data
to change the format of the request sent to the server. Are you asking to change the format to JSON? If yes then see the last example in theajax.data
docs. Otherwise useajax.data
as a function to change to the desired format.Kevin
I can't understand. can you show me an example?
sure JSON is good...
but I want to send data with request parameter
.../pagination?draw=1&columns[0].data=first_name&...
I need an example for it
thanks
As I said the last example in the
ajax.data
docs show how to convert the request to JSON. Here is the code from the example:Kevin
Thank you very much
Can I send data looks like this ? (parameter request)
You will need to use
ajax.data
as a function to manipulate the original format sent to the server to the format you want. There is nothing built into Datatables to convert the default parameters to the format you want.Kevin
Thank you dear
I have to remove [] and send them.
thanks a lot
Excuse me. In the continuing this discussion...
I used
searchBuilder
and I know the searchBuilder doesn't callajax.data
and this function is unused !!!and doesn't call it
my code is:
And I have this error after 2 times click on
refresh
button orsearch
buttonmy breakpoint is unused. my function
jsonToQueryParams(d)
doesn't work any more.thanks
Based on a couple other threads it sounds like SearchBuilder adds it's parameters after
ajax.data
is called. Modifying the data structure seems to cause this error. See these threads:https://datatables.net/forums/discussion/comment/223786/#Comment_223786
https://datatables.net/forums/discussion/76464
Looks like someone was able to use jQuery ajax()
beforeSend
to modify the data when using SearchBuilder. Try addbeforeSend
to theajax
option.@allan will need to comment on if there is a better way to handle this.
Kevin
So sorry, I can't understand your answer.
d.SearchBuilder
is always undefinedThat isn't an option in jQuery's Ajax handling. HTTP parameters are always sent with
[]
for objects and arrays. As far as I am aware there is no way to override that in jQuery. Most server-side parsers will expect it in the[]
format anyway.What are you using on the server-side that expects it in
columns[0].data
format?You can send pure JSON to the server in the request body - last example in the
ajax.data
docs. That might allow you more options at the server-side?It would be helpful if you could explain what the problem at the server-side is - i.e. why do you need to do this?
Allan
Thank you
I used Spring boot (Java). Java only understands this format:
But
datatables
send this format:both of them is correct in
Javascript
, but not inJava
I have this error
I want to send data with type of
GET
, so I needQuery Params
and notJSON
.I've just read over the jQuery Ajax docs, and I don't see any way to get the format you are looking for, for the parameter keys.
I think you'll need to ask on StackOverflow or a Java specific forum about how to parse data in the
a[b][c]
format. I'm afraid I have virtually no knowledge of Java.One possibly option is that you could assign JSON to an HTTP parameter:
And then at the server-side decode the
json
parameter. Might be an option? But yeah, for the format that is sent, I'l afraid you'll need to ask in a Java support forum.Allan
Thank you very much. Is it possible you create a feature for it at next version?
Thank you
Can you answer for second question?
About
SearchBuilder
Where are you trying to access
d.SearchBuilder
?The threads I posted indicate that the searchBuilder parameters are added after both the
ajax.data
andpreXhr
events. I modified one of the examples in the threads I linked to above to show this:https://live.datatables.net/gupumija/8/edit
Perform a searchBuilder search and you will see the searchBuilders parameters aren't added in
ajax.data
orpreXhr
. However, in beforeSend the parameters are there. As suggested in the second thread try making the modifications in the beforeSend.Kevin
Very unlikely I'm afraid. This is the first request for that submission format that I can recall, and I just use jQuery to submit data via
jQuery.ajax
- the change would need to be there.Allan
Thanks a lot. It's answer so completly.
And Thanks a lot @allan too