After updating DataTables and ColReorder: TypeError: g.aoColumns[a.aaSorting[f][0]] is undefined

After updating DataTables and ColReorder: TypeError: g.aoColumns[a.aaSorting[f][0]] is undefined

jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

Hello

I just downloaded the latest versions of DataTables and ColReorder (primarily to make use of the new html5 data- attribute for sorting).

After doing so, I am getting this error: "TypeError: g.aoColumns[a.aaSorting[f][0]] is undefined" referencing ColReorder.js.

I have tried with a variety of options, and have set up various minimal test tables and run into the problem in all of my cases (so long as ColReorder is called).
This stops the ColReorder, and anything called after it, not to work.

Debug info here: http://debug.datatables.net/ixuwih

Any tips? I am stuck.

thanks!

This question has an accepted answers - jump to answer

Answers

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1
    edited May 2014

    on further investigation, it appears to happen only when state save is set to true.
    State save is a required feature, however, so I can't just turn it off.

    This is the bit relevant to bStateSave:

    bStateSave      : true, fnStateSave     : function (oSettings, oData)   { localStorage.setItem( 'DataTables_test-        table_'+window.location.pathname, JSON.stringify(oData) );     }, fnStateLoad     : function (oSettings)          { return JSON.parse(       localStorage.getItem('DataTables_test-table_'+window.location.pathname) );       }, iCookieDuration : 1209600,
    

    Is there anything that needs to change here, with the latest version?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can you link to a test case showing the problem?

    You don't need fnStateSave etc in 1.10 now as it uses localStorage by default :-)

    Allan

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

    Sorry, I thought the debug link would suffice for the test case.

    I am trying to rebuild my code in the new manner right now, and will put together a test case from that (currently, my code is built by a couple of dynamic methods that make it a little complex to pull a static example from).

    thanks.

    On another note - with the new stateSave method, how do I access the saved state in order to remove it?

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

    Ok, I have a test version here: http://jsfiddle.net/jlbriggs/Swa7f/

    But it doesn't appear to be doing the stateSave, or it is not retrieving the state save, so it is not showing the error.

    On the other hand, on my server, it appears to be saving and retrieving the state, even when I tell it not to....?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    The state appears to work okay for me in your link. If I have it page to show records 46 to 60 of 63 and then click the JSFiddle Run button to rerun the script the page is restored. Is that not happening for you?

    Allan

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

    Apologies - the stateSave is working for me on fiddle. I must have been doing something to negate it previously. The issue with it saving on my server despite being set false was a fluke as well.

    I am still trying to get the initial problem to duplicate in the fiddle, as I still have not fixed it on my server.

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1
    edited May 2014

    I still can't seem to reproduce the problem on the example version.

    However, I have narrowed it down a little after updating my code to work with the new methods.

    • If the page loads, and there is no previously saved state, everything is fine.
    • If the user does not sort, filter, or otherwise alter the table, every time it loads it will be fine.

      • if the user sorts, filters, or otherwise alters the table, and the state is saved, the next time the page loads, the originally posted error appears.
    • after that event, when the page is loaded again, every thing is fine until the next time the state changes and needs to be reloaded....

    I know that doesn't give you what you need to solve my problem, but if anyone has any tips on where I can focus given this information, I would appreciate it.

    thanks,
    Jamie

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi Jamie,

    First suggestion would be to use the unminified version of DataTables and ColReorder. What line does it break on when that is the case?

    Also, can you confirm that the number of columns is not changing?

    Allan

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1
    edited May 2014

    AH, yes, meant to include that.

    Line 739 of ColReorder, which is this bit:

    /* Sorting */
    
            for ( i=0 ; i<oState.aaSorting.length ; i++ )
    
            {
    
                oState.aaSorting[i][0] = oSettings.aoColumns[ oState.aaSorting[i][0]     
    
    
    ]._ColReorder_iOrigCol;
    
            }
    

    I am using the ColVis extension as well, but this problem appears without columns being hidden, so yes - the number of columns stays consistent.

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

    Anyone have any further thoughts on this?

    I am at a loss...

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

    newly discovered: when the page does load and initialize error free, the same error as posted above appears if I enter any text into the global table filter input (though it does not occur when using the individual column filters).

  • jlbriggsjlbriggs Posts: 15Questions: 2Answers: 1

    Ok, so it appears that this must be a known issue?

    Solution: download this Git commit: https://github.com/DataTables/DataTables/commit/77343b72cb035e1ceba387335136f010282c0940

    Or, link to the CDN using the nightly builds of the core DataTables file.

    I have download the commit, and so far everything appears to be working properly for me.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    Hi,

    Sorry for the delay in being able to reply. Excellent to hear that the fix in the nightly is working for you. Planning to release 1.10.1 with it, and several other fixes next week.

    Allan

This discussion has been closed.