aoData null when using turbolinks

aoData null when using turbolinks

maciusplmaciuspl Posts: 7Questions: 0Answers: 0
edited February 2014 in General
Hi,

First of all I'm not experienced javascript programmer. I'm using in my application turbolinks. When I make full page reload everything is fine with datatables, but when I go to another page and back oTable.fnGetData(rowIndex) throws Cannot read property 'aoData' of null. Why aoData is null. Is there any easy solution for this problem?

Thanks for help, regards!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    As per the forum rules, please link to a test case showing the issue.

    Allan
  • maciusplmaciuspl Posts: 7Questions: 0Answers: 0
    This is my scenario without turbolink's functionality. If it doesn't help with finding solution I will try to add turbolinks functionality (Dunno how now). I left comments in code.

    http://live.datatables.net/idinat/16/

    Thank you very much !
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    In all honestly, I don't even know what "turbolink" is...

    However, you are passing in a row id into fnGetData . It expects a node or an index - _not_ an id.

    Just use:

    [code]
    var data = table.fnGetData( $(this).parents('tr')[0] );
    [/code]

    rather than than mucking around with ids.

    Allan
  • maciusplmaciuspl Posts: 7Questions: 0Answers: 0
    This doesn't help. Still getting this error:

    Uncaught TypeError: Cannot read property 'aoData' of null jquery.dataTables.js?body=1:5715
    fnGetData jquery.dataTables.js?body=1:5715

    Turbolinks allows you to change only body and the title in the head of your site instead downloading css and js everytime. I think it is something similiar to pjax if you heard.

    Do you have any idea ?

    Thanks !
  • maciusplmaciuspl Posts: 7Questions: 0Answers: 0
    I know this is probably not bug in data tables (rather integration dt with turbolinks) but with your little help and knowledge I will find out what is not right :)

    Thank's for help !
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It seems to work okay for me: http://live.datatables.net/idinat/18/edit . When you click a details button it shows the row's data on the console.

    Allan
  • maciusplmaciuspl Posts: 7Questions: 0Answers: 0
    With normal request everything is fine. I have problem when with turbolink's, cause I go to another page using pushState (https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#The_pushState().C2.A0method) method.

    To reproduce the problem I must go to site with datatable go to another site using push state (Turbolink) and go back to datatable site, then I have aoData null.

    Caveats: After change page (via pushState, read Turbolink) the global js is not cleaned.

    Thanks for your time :)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That sounds well beyond the scope of DataTables now. You might be best asking on a generic Javascript forum or something specifically for TurboLink.

    Allan
This discussion has been closed.