State loading and saving for plug-ins

State loading and saving for plug-ins

twiglet36twiglet36 Posts: 3Questions: 0Answers: 0
edited February 2012 in Plug-ins
Hi,

I'm writing a plug-in to handle row selection for server-side DataTables (effectively a wrapper around Iuliandum's technique at http://datatables.net/examples/server_side/select_rows.html) , but I'm having some difficulty understanding the plug-in API for loading state. I've got as far as knowing that I have to subscribe to the stateLoadParams event (http://datatables.net/docs/DataTables/1.9.beta.2/DataTable.html#stateLoadParams) but I'm not actually sure how to do this!

If anyone has any examples of loading state in a plug-in initialiser I would be most grateful.

Thanks

Ben

Replies

  • twiglet36twiglet36 Posts: 3Questions: 0Answers: 0
    I put the folloiwng line in the "fnInit" function of the plug-in:

    [code]
    var dataTable = oDTSettings.oInstance;
    dataTable.bind('stateLoadParams', function() {
    // do something here
    });
    [/code]

    After double-checking my binding it became evident that the problem is that stateLoadParams is fired before the plug-in is initialised (so it never gets fired). Any workarounds/fixes?
  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin
    It depends a little bit about how you are initialising your plug-in - the stateLoadParams event actually happens very early on in the initialisation of DataTables, so I suspect that your plug-in will be missing this event (it certainly will if you are using sDom to create a feature plug-in). What I would suggest is that you look at the oSettings.oLoadedState object when your plug-in is initialisation. If there is state information available front he loaded, it will be in there.

    Allan
  • twiglet36twiglet36 Posts: 3Questions: 0Answers: 0
    Hi Allan

    oLoadedState worked perfectly. Many thanks for such an excellent control!

    Ben
  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin
    Nice one - thanks for the feedback on this problem :-)

    Allan
This discussion has been closed.