Strange behavior of fnSettings()

Strange behavior of fnSettings()

leurkleurk Posts: 5Questions: 0Answers: 0
edited June 2011 in General
Hello.

I use DataTables 1.8.0 with sAjaxSource/fnServerData and fnReloadAjax plugin to post-process server data on client side. Inside fnServerData callback there is a need to access table settings so I use this.fnSettings() construct (see test case code below).

When table gets created, this.fnSettings() call returns proper object. However on later fnReloadAjax calls (notice extra oTable.fnReloadAjax () call in test case below) browser throws the error: "this.fnSettings is not a function" (Firefox/Opera) or "Object # has no method 'fnSettings'" (Google Chrome).

Using this.fnSettings() inside nRowCallback works as expected no matter how many times fnReloadAjax was called.

I strongly believe there is a bug.

jQuery 1.4.4, browsers tested: Firefox 4.0.1, Opera 11.11, Google Chrome 12.

Alexey

[code]







var testData = { "aaData": [
{
"engine": "Trident",
"browser": "Internet Explorer 4.0",
"platform": "Win 95+"
},
{
"engine": "Trident",
"browser": "Internet Explorer 5.0",
"platform": "Win 95+"
}
] };

var _fnServerData = function ( sSource, aoData, fnCallback ) {
//var oSettings = this.fnSettings (); /* this.fnSettings is not a function. */
fnCallback ( testData );
}

var _fnRowCallback = function ( nRow, aData, iDisplayIndex ) {
var oSettings = this.fnSettings ();
return ( nRow );
}

$( document ).ready ( function () {
var oTable = $( '#testTable' ).dataTable ( {
"sAjaxSource": "/foo",
"fnServerData": _fnServerData,
"fnRowCallback": _fnRowCallback,
"aoColumns": [
{ "mDataProp": "engine" },
{ "mDataProp": "browser" },
{ "mDataProp": "platform" }
]
} );

oTable.fnReloadAjax ();
} );









[/code]

Replies

  • leurkleurk Posts: 5Questions: 0Answers: 0
    edited June 2011
    Looks like I get it.

    In contrast with table initialization stage, "this" already points to oSettings during ajax update and there is no need to call fnSettings (). Following code did the trick for me.

    [code]
    rv.fnServerData = function ( sSource, aoData, fnCallback ) {
    var oSettings = ( this.fnSettings ) ? this.fnSettings () : this;
    ...
    }
    [/code]
This discussion has been closed.