fnServerData's 4th parameter

fnServerData's 4th parameter

korukyukorukyu Posts: 11Questions: 0Answers: 0
edited July 2012 in General
According to the reference, fnServerData takes a 4th parameter of oSettings, which is a DataTables settings object.

Does anyone know what this is for? Can it be used to change settings set in the initialization of the table? I can't find any reference on it.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    edited July 2012
    The settings object is fully documented in the DataTables 'generated' documentation: http://datatables.net/docs/DataTables/1.9.1/DataTable.models.oSettings.html .

    > Does anyone know what this is for?

    It holds the current state of your table. DataTables is not currently instances based, but 'settings based' - each settings object describes a DataTable.

    > Can it be used to change settings set in the initialization of the table?

    I could be, but you need to be darn sure you know what you are doing with it. You'd be much better to use the public API: http://datatables.net/api .

    Allan
  • korukyukorukyu Posts: 11Questions: 0Answers: 0
    edited July 2012
    @allan Well, I'm not too sure I know what I'm doing, so... I wasn't sure if the oSettings that you pass in through fnServerData was the same as the oSettings that fnSettings returns.

    Actually, it looks like fnSettings is the only method in the api that works with table settings. But it returns the settings. Can you also use it to set/modify them?

    And as a random aside, how do you get to that docs page you linked? I've never even seen that before. Is it linked from the main site, and I'm just totally blind?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > I wasn't sure if the oSettings that you pass in through fnServerData was the same as the oSettings that fnSettings returns.

    It is yes :-).

    > Actually, it looks like fnSettings is the only method in the api that works with table settings.

    Its the way of getting direct access, but if you want to change column visibility (a setting) then you would use fnSetColumnVis - fnFilter for filtering (another setting) etc.

    > Is it linked from the main site, and I'm just totally blind?

    Generally no actually, for part of the reasons we discuss above. HAving said that is it in the "docs" directory of the DataTables download.

    That documentation is effectively the developer documentation for plug-in authors and those working directly with the DataTables settings object - which as I say you need to know what you are doing before tinkering with it. For example, say you want to change how the search results get there data - you might want to work directly with _aSearchData - but DataTables will obliterate any changes on the next filter...

    For this reason the "Usage" and "API" sections that make up the main body of the interface documentation on this site discuss only the public API.

    Allan
  • korukyukorukyu Posts: 11Questions: 0Answers: 0
    [quote] Its the way of getting direct access, but if you want to change column visibility (a setting) then you would use fnSetColumnVis - fnFilter for filtering (another setting) etc. [/quote]

    I guess that makes sense. But I can't seem to call fnServerData after initialization, which was why I was attempting to get into oSettings.

    I want to periodically make additional ajax calls to keep the table updated, so I'm trying to figure whether I should make an ajax call then run fnUpdate for every row, or if I can just do it the same way as I do when I made the table the first time, with fnServerData and fnCallback.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > But I can't seem to call fnServerData after initialization, which was why I was attempting to get into oSettings.

    fnServerData isn't a callback - its an initialisation option with a function that you can tell DataTables how to get data. So to "call it" just make DataTables redraw the table (i.e. fnDraw ) - assuming you are using server-side processing.

    If you aren't - then use the fnReloadAjax plug-in: http://datatables.net/plug-ins/api#fnReloadAjax

    Allan
  • korukyukorukyu Posts: 11Questions: 0Answers: 0
    Ohh. Yeah, I didn't realize redrawing the table would do another ajax call. I'm not sure what things only happen at initialization vs. what happens during a redraw. Does fnDrawCallback occur after a draw finishes, or right before?


    Now if I can just get $.fn.dataTable.defaults to work maybe I'll be able to get this code working sometime this week.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > Ohh. Yeah, I didn't realize redrawing the table would do another ajax call.

    If you are using server-side processing, yes.

    > Does fnDrawCallback occur after a draw finishes, or right before?

    After. fnPreDrawCallback happens before.

    Allan
This discussion has been closed.