Can someone explain how this works?

Can someone explain how this works?

kennyrkennyr Posts: 3Questions: 0Answers: 0
edited April 2013 in Plug-ins
I'm working with the plugin for individual column filtering, and there's a part of the code that I don't understand:

[code]$.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {[/code]

The explanation in the comments states that oSettings is always the last argument passed in, yet how can it be, if it is the first argument in the function?

Furthermore, the only thing being passed in is the index of the current column, (0-5), and somehow, those values are in fact making it into the second parameter, iColumn, where they belong.

What am I missing here? How is it possible that passing one argument would skip over the first one in the function definition, and land in the proper place like that?

To confuse me even more, I noticed that oSettings somehow appears to have the correct information in it, even though it's not being passed in.

Can someone clarify this for me? There is obviously something going on here that I'm not aware of...

Thanks,

Kenny

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > The explanation in the comments states that oSettings is always the last argument passed in

    The _first_ parameter, not the last one. From the plug-ins page:

    > Please note that DataTables will automatically pass the settings object as the first parameter.

    If the documentation anywhere says that it is the last parameter - it is wrong. Does it say that somewhere that I missed?

    > To confuse me even more, I noticed that oSettings somehow appears to have the correct information in it, even though it's not being passed in.

    When DataTables registers fnGetColumnData it wraps the plug-in up in another function which implements the argument shifting.

    This is a fairly ugly solution to the problem. DataTables 1.10's new API will be much cleaner in this regard and allow you to do something as simple as `table.column( 1 ).data()` rather than needing the plug-in with its annoying settings object.

    Allan
  • kennyrkennyr Posts: 3Questions: 0Answers: 0
    Allan,

    Thanks for your reply. Glad to know that things will get clearer as we go on. I only recently found DataTables, and so far I'm loving it!

    The instructions on line 6 of the demo code on the following page says "last" instead of "first", and also uses the word "past" instead of "passed". http://datatables.net/release-datatables/examples/api/multi_filter_select.html

    Hope that helps make things better. Thanks for jumping in to explain and clarify things for me.

    Kenny
This discussion has been closed.