Data Format for Server Side
Data Format for Server Side

Hello,
I want to send paginated data to DataTables from my Spring based backend. So far I have managed to get the response to look like:
{
"draw":1,
"recordsTotal":57,
"recordsFiltered":57,
"data":[
{
"salesno":"P12345",
"start_date":"01/09/2017",
"address":"2 Some Road, Los Angeles",
"Entry":false,
"names":"PITT & ANISTON"
},
Question: Do I need to change the inner { to [ - like below:
{
"draw":1,
"recordsTotal":57,
"recordsFiltered":57,
"data":[
[
"salesno":"P12345",
"start_date":"01/09/2017",
"address":"2 Some Road, Los Angeles",
"Entry":false,
"names":"PITT & ANISTON"
],
And if so what would the best way to do this be? Client or Server side? And if Client side does DataTables have a way to help with this situation?
Thanks
Al
This question has accepted answers - jump to:
This discussion has been closed.
Answers
And my client side code:
I'm doing much the same as you with a Spring back end. My response data is as in your first example and it's working fine.
No - what you've shown isn't actually valid JSON. You could use an array, or you can continue to use an object - its up to you. This section of the manual has more information about both.
Allan
Thank rduncecb - thats a good sanity check that I am on the right track.
I had another look at it this morning when I wasn't so tired and its going now.
@allan thanks too. That link cleared a few things up.
@rduncecb in the request are you using the start property to work out which page and what data to send to front end?
Also does start in sent parameters indicate the record index out of total, or page index?
The first question to ask is if you actually need server-side processing? Are you using tens of thousands or more rows? If so fine, carry on with server-side processing - the manual for it is here.
If not, then drop the
serverSide
option and just use client-side processing. It will save you needing to worry about the paging on the server-side.Allan
Hello allan.
I need to format decimal to currency in server side datatable.
My Data which I return in Page is { "mData": "TotalAmount" } I need to display the result in format of e.g 10,000,000.00 instead of e.g 232206368.75
@gkahana - I replied on your other thread.