fnInitComplete what is "this" bound to?

fnInitComplete what is "this" bound to?

TomCTomC Posts: 43Questions: 0Answers: 0
edited March 2010 in General
Given:
[code]
oTable = $("#datatable").datatable( {
"fnInitComplete" : function(){ console.log(this) }
});
[/code]

Why isn't oTable == this?
"this" seems to reference a datables related object but it is missing some key methods.

Replies

  • TomCTomC Posts: 43Questions: 0Answers: 0
    Ok so I see in the documentation that this return a dataTables settings object which has some useful data. Is there some callback that returns the oTable object?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi TomC,

    The value of 'this' in fnInitComplete is currently the DataTables settings object for the table in question (since the function was executed in that scope). I think executing the call back functions with 'this' actually being the DataTables object is a much better idea, and I'll look at the possibility of including this in 1.7.

    Regards,
    Allan
  • aaronwaaronw Posts: 89Questions: 3Answers: 4
    Allan: Did 'this' get changed to the DataTables object vs the settings object?

    It looks like it did, but http://www.datatables.net/usage/callbacks still says it returns the settings object.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi aaronw,

    fnInitComplete does indeed execute with the scope of the DataTables instance, as should all callback functions in DataTables. Some might return the settings object (fnSettings for example), but all should execute with the same scope. Is it the documentation for fnInitComplete you are referring to?

    Thanks,
    Allan
  • aaronwaaronw Posts: 89Questions: 3Answers: 4
    Yes fnInitComplete function appears to use 'this' to mean the table object vs the settings object (of course, my javascript knowledge is not the best, so I'm willing to be corrected.
This discussion has been closed.