Change settings in the runtime

Change settings in the runtime

vuceticavucetica Posts: 15Questions: 0Answers: 0
edited October 2009 in General
I can get the settings object with fnSettings() function. Is there a way to set those settings in the runtime if I have this object stored/serialized somewhere. Something like this:

[code]
var settings = oTable.fnSettings();
...
oTable.fnSettings(settings);
[/code]

Thanks!

Replies

  • allanallan Posts: 61,758Questions: 1Answers: 10,111 Site admin
    Hi vucetica,

    To do what you are looking for there, you need to make a deep copy of the settings object, and then copy it back over the in use settings object when you want to restore it. The key thing here is that objects are stored/passed by reference in Javascript (a bit like pointers in C).

    So step 1: Deep copy settings object to a variable (i.e. using $.extend() )
    Step 2: To restore - you'll need to write your object back over (ideally a return deep copy) the element of $.fn.dataTableSettings[] that you originally copied

    Bit of a technical one this one...

    The easier way would be to simply save the attributes you want (display start, search etc) and then restore them. Although you might still run into problems with the arrays which are used...

    Regards,
    Allan
This discussion has been closed.