bRetrieve works incorrectly
bRetrieve works incorrectly
lvu
Posts: 1Questions: 0Answers: 0
Hi!
There seems to be a bug in bRetrieve parameter handling, which leads to retrieval of an object different from the one created previously, although very similar. For example:
[code]
var tbl = $('table#data').dataTable();
tbl.foo = 'bar';
var tbl2 = $('table#data').dataTable({bRetrieve: true});
tbl2.fnDraw(); // this works
alert(tbl2.foo); // where is my foo?!
[/code]
This happens because when dataTable({bRetrieve: true}) is called, "return _aoSettings[i].oInstance;" statement inside .each() method does not do what expected. In fact, it does nothing, as .each() only pays attention to false-equivalent return values of its argument functio, and always returns "this" object.
Built-in dataTables functions work on retrieved object simply because it is almost completely initialized when it comes to bRetrieve checking. But it is not the same object.
The simple workaround, that also eliminates unnecessary object initialization, is to add to the very beginning of $.fn.dataTable function something like this:
[code]
// Looking for existing datatable if needed
if ( typeof oInit != 'undefined' && typeof oInit.bRetrieve != 'undefined' && oInit.bRetrieve === true )
{
var result = undefined;
this.each(function(){
for ( i=0, iLen=_aoSettings.length ; i
There seems to be a bug in bRetrieve parameter handling, which leads to retrieval of an object different from the one created previously, although very similar. For example:
[code]
var tbl = $('table#data').dataTable();
tbl.foo = 'bar';
var tbl2 = $('table#data').dataTable({bRetrieve: true});
tbl2.fnDraw(); // this works
alert(tbl2.foo); // where is my foo?!
[/code]
This happens because when dataTable({bRetrieve: true}) is called, "return _aoSettings[i].oInstance;" statement inside .each() method does not do what expected. In fact, it does nothing, as .each() only pays attention to false-equivalent return values of its argument functio, and always returns "this" object.
Built-in dataTables functions work on retrieved object simply because it is almost completely initialized when it comes to bRetrieve checking. But it is not the same object.
The simple workaround, that also eliminates unnecessary object initialization, is to add to the very beginning of $.fn.dataTable function something like this:
[code]
// Looking for existing datatable if needed
if ( typeof oInit != 'undefined' && typeof oInit.bRetrieve != 'undefined' && oInit.bRetrieve === true )
{
var result = undefined;
this.each(function(){
for ( i=0, iLen=_aoSettings.length ; i
This discussion has been closed.
Replies
So what you can do is just use the first element in the array, which is persistent: http://live.datatables.net/omexal/edit#javascript,html
Allan