Using DataTables live
Using DataTables live
Can I get an explanation of how to use DataTables live. I am using Rails and my web page crashes with the common 'aData' is undefined. Specifically how do I assemble the javascript components, the DataTables params and the json options etc which are all built within the Rails framework?
This discussion has been closed.
Replies
Using the debugger might give us a clue as to why you are seeing the error you are.
Allan
The debug url: http://debug.datatables.net/uniyon
When I step through the code (_fnGetObjectDataFn) oSettings.sAjaxDataProp = "", so it drops through to the last return (/* Array or flat Object mapping */). The json I see in Firebug Watch looks OK in that it is the correct data, but does not include the aaData etc.
However if I enter http://localhost:3000/highways/list.json into the browser then I see:
{"sEcho":0,"iTotalRecords":229,"iTotalDisplayRecords":229,"aaData":[["ALBANY HIGHWAY","WA","STATE 30",null,1],["ANNE BEADELL HIGHWAY","SA","ANNE BEADELL HIGHWAY",null,2], ...
Firebug > Console > All > Parameters for the GET look OK. I have had an experienced Rails person look at that code and he could not see a problem. I have had a question on StackOverflow for 11 days without a response.
So I am not sure where to look next. On the face of it it looks as if Rails isn't serving up the correct json. My code is based on Ryan Bate's RailsCasts #340 - he checked my code and could not see anything wrong. By the way I had this working in a test case some months ago and I I have done a diff on the relevant code files, between the two versions, and could not see any differences.
Hope you can help, or point me in a different direction.
Regards
John
You've got server-side processing enabled, but you aren't returning the parameters required by server-side processing in your JSON response. See: http://datatables.net/usage/server-side - you must return sEcho, iTotalRecords etc.
Are you sure you actually want server-side processing?
Allan
Yes I do prefer server-side processing. I already have thousands of rows in some tables. You have confirmed for me that the json DataTables sees does not have the parameters. What is confusing to me is why entering http://localhost:3000/highways/list.json into the browser I see:
{"sEcho":0,"iTotalRecords":229,"iTotalDisplayRecords":229,"aaData":[["ALBANY HIGHWAY","WA","STATE 30",null,1],["ANNE BEADELL HIGHWAY","SA","ANNE BEADELL HIGHWAY",null,2], ...
which I presume is what DataTables would expect to receive.
Since both versions are delivered by Rails I am not sure what is going on. My Rails code is supposed to return the parameters and I have had that checked. Since you have confirmed that DataTables is not receiving the parameters ( I guess you can see this from the debug) I will now post this precise question on StackOverflow to get more help on the Rails side.
Thanks for you assistance. If I find a solution I will let you know.
John
Your DataTable is loading from: http://localhost:3000/highways.json . Might that be the difference?
Allan
[code]
"sAjaxSource": "http://localhost:3000/highways.json",
[/code]
Allan
Sorry my mistake. I was typing in the wrong url. That http://localhost:3000/highways.json shows the json without the parameters, and as you have found the debug trace shows that path. So you have narrowed it down for me. I think that this is now a Rails question.
When I go to http://localhost:3000/highways/list Rails goes to my 'list' action which renders the data from the server as json in the context of the 'list' view. But my 'list' view is trying to use http://localhost:3000/highways.json NOT http://localhost:3000/highways/list.json.
Thanks!
John
Allan