fnInfoCallback

fnInfoCallback

FParsonsFParsons Posts: 18Questions: 3Answers: 0
edited November 2012 in General
DataTables has a callback named "fnInfoCallback". At first I thought this would be the equivalent of a "onFilterCallback" (actions to take every time a filter is applied) - but I found that this callback *only* works if the sDom property includes the filter input. (To get around this I applied a class in the sDom property to make it invisible).

Basically, I'd like to be able to display the table information somewhere other than in Datatables generated elements (I think many others would like to do this too.) While you can do this by using the "fnInfoCallback", it seems illogical to me that you need to hide the filter input in order to do this. Is this a bug by any chance? (Was it intended to work this way?) Could this be something addressed in a future version?

Replies

  • FParsonsFParsons Posts: 18Questions: 3Answers: 0
    Just a correction to the above - it's not the filter input that needs to be present, it's the "info display" element.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    > Just a correction to the above - it's not the filter input that needs to be present, it's the "info display" element.

    Phew - you had me worried for a second there :-).

    This is working exactly the way it was intended - the callback is there specifically to modify the text that will be shown in the information display. If you aren't showing the text, why would you need the callback to modify said text?

    If you want something to occur on each draw, there is fnDrawCallback available.

    Allan
  • FParsonsFParsons Posts: 18Questions: 3Answers: 0
    Well, I guess I don't have a great reason, but the "fnInfoCallback" does have the convenience of having the parameters "oSettings, iStart, iEnd, iMax, iTotal, sPre". I know you can access these from the settings object, but as far as I can tell many of these aren't listed in the documentation (you need to go into the source code find them).

    <
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Sounds like you might find this API plug-in method useful: http://datatables.net/plug-ins/api#fnPagingInfo .

    The DataTables API with the advent of v1.10 will include this kind of information in the built-in public API :-)

    Fair point about using the info callback to populate some other element. That sounds like a good reason to make the required change to me (note made for inclusion in 1.10 - there will just be an `if` condition).

    Another option might be to move the DataTables controlled info element to somewhere else in the DOM after the table has initialised. Not really a common thing to do, but it is possible.

    Allan
  • FParsonsFParsons Posts: 18Questions: 3Answers: 0
    Allan - thanks for the link, I ended up using just the settings object with the "draw" callback. I do remember reading the roadmap for future versions including a public API for settings, and I look forward to it!
This discussion has been closed.