Reload Datatable Viewer with new AJAX Source .load()
Reload Datatable Viewer with new AJAX Source .load()

I am using the client side version of datatabes viewer and editor to work with AJAX sourced JSON data.
It seems like a simple thing, but I can't seem to get this to work.
I need to clear the table and load new data on demand using another query. Same, structure same endpoint, just different query string operations.
I have tried to use ajax.url().load() , which seems like the right thing do use, but my server produces data in the following format:
[{
"Comments": "",
"Hours": 5.5,
"Lunchbreak": 5.5,
"ClockOut": "2017-04-19T17:00:00",
"ClockIn": "2017-04-19T06:00:00",
"WorkDateKey": "2017-04-20T00:00:00",
"UserID": "BVelasquez",
"SeqNumForFrontEnd": 1066
}]
Not the format datatables would like:
{
"data": [
{
"DT_RowId": "row_29",
"first_name": "Fiona",
"last_name": "Green",
"position": "Chief Operating Officer (COO)",
"office": "San Francisco",
"extn": "2947",
"salary": "850000",
"start_date": "2010-03-11"
}
]
}
I'm my initialization, I use the "dataSrc": "" and everything works like a dream. But when I try to load the new data using ajax.url().load(). It doesn't like it
How do I use ajax.url().load() and still be able to tell the viewer to expect the format in a plain array and not an object?
This question has accepted answers - jump to:
Answers
I believe the same
dataSrc
is used when usingajax.url().load()
. Looks like you are returning an array of objects and it sounds like the same structure is returned when usingajax.url().load()
. But its not working for you. What errors do you get?Maybe you can post your Datatables code and the JSON results from the initial load and the
ajax.url().load()
.Kevin
Yup, Kevin is spot on as usual.
ajax.dataSrc
will be reused when usingajax.url().load()
, so you need to make sure it is returning the same structure as when the table was initially loaded.Allan
Thank you so much guys, that is what I thought ~ it turns out my query was just wrong.
I was using a "YYYY/MM/DD" format when I should have been using a "YYYY-MM-DD" format in my query string. Silly me, thanks Kevin and Allan for the quick reply.