Modify aoColumns from callback function

Modify aoColumns from callback function

F30_norisF30_noris Posts: 4Questions: 0Answers: 0
edited August 2013 in DataTables 1.9
Howdy,

our application dynamically modifies the 'bSearchable' attribute of columns and we'd like to restore that state later.
Therfore, I use the 'fnStateSaveParams' callback to store the selection in a cookie.

What leaves me puzzled so far is how to restore it: Both 'fnStateLoadParams ' and 'fnStateLoaded' fire at a stage where the 'aoColumns' array is not yet populated and its future state is stored in 'oInit' instead. 'oSettings.oInit' doesn't contain the same object and therefore doesn't help me either.
What I apprently needed, was a way to access 'aoColumnsInit' or oInit' from the callback function – but this is oviously not possible. So is there another easy way to achieve the desired effect?

Thanks a lot in advance!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You can access it through oSettings.oInit - http://datatables.net/docs/DataTables/1.9.4/DataTable.models.oSettings.html#oInit .

    In fairness I hadn't really expected it to be used quite that way - but it does sound like a sensible use in retrospect!

    Allan
  • F30_norisF30_noris Posts: 4Questions: 0Answers: 0
    edited August 2013
    Unfortunately this does not work, as I said: "'oSettings.oInit' doesn't contain the same object and therefore doesn't help me either."

    Having dived into the DataTables source, the reason for that seems to be that 'oSettings.oInit' starts out as a deep copy of the actual 'oInit' object:

    [code]
    var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
    ...
    "oInit": oInit,
    ...
    } );
    [/code]

    But afterwards, a lot of funky stuff happens to 'oInit', which doesn't get applied to 'oSettings.oInit'.
  • F30_norisF30_noris Posts: 4Questions: 0Answers: 0
    *Push*

    No way to do this? :-(
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sorry - I missed that bit.

    Could you possibly try this with v1.10 please: https://github.com/DataTables/DataTables/tree/1_10_wip/media/js ? Column detection happens before the state is resolved in v1.10 (which is currently pre-beta).

    Allan
  • F30_norisF30_noris Posts: 4Questions: 0Answers: 0
    edited August 2013
    Thanks, using 1.10-dev it works fine to just modify 'oSettings.aoColumns' in a 'fnStateLoadParams' function.
    Guess I'll wait till 1.10 is stable then.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I would say 1.10 is quite stable. The only reason its not in beta at the moment is that I've not been able to write the documentation for it yet! It will go beta as soon as I can do that.

    Allan
This discussion has been closed.