Using DataTables live

Using DataTables live

need2surfneed2surf Posts: 5Questions: 0Answers: 0
edited February 2013 in General
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?

Replies

  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    DataTables live as in http://live.datatables.net ? It is typically used for only Javascript manipulation with the standard resources - unless you set your server / application up for cross domain checking.

    Using the debugger might give us a clue as to why you are seeing the error you are.

    Allan
  • need2surfneed2surf Posts: 5Questions: 0Answers: 0
    Hi 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
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    Hi 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
  • need2surfneed2surf Posts: 5Questions: 0Answers: 0
    Hi 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
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    > What is confusing to me is why entering http://localhost:3000/highways/list.json into the browser I see: [...]

    Your DataTable is loading from: http://localhost:3000/highways.json . Might that be the difference?

    Allan
  • need2surfneed2surf Posts: 5Questions: 0Answers: 0
    No I don't think so. The view that comes up is only invoked by the 'list' action in the Rails controller. The jQuery theme and column structure is correct and consistent with the view of the same name ie "list'. I tried entering http://localhost:3000/highways.json , but it is not a valid route in my application.
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    If it isn't a valid route, how is it loading at all? Your debug trace shows:

    [code]
    "sAjaxSource": "http://localhost:3000/highways.json",
    [/code]

    Allan
  • need2surfneed2surf Posts: 5Questions: 0Answers: 0
    Hi 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
  • allanallan Posts: 63,205Questions: 1Answers: 10,415 Site admin
    With just 229 records , you could just use client-side processing and save yourself a good bit of hassle! DataTables is already reading all the data, so let it use it :-). Server-side processing should only really be needed with 50'000+ rows in modern browsers anyway (much less for IE6...).

    Allan
This discussion has been closed.