fnFilterAll plugin possible bug

fnFilterAll plugin possible bug

cdrwf150cdrwf150 Posts: 6Questions: 0Answers: 0
edited February 2011 in Plug-ins
I think you need to add jQuery.fn.dataTableExt.iApiIndex = 0; after the forloop.

[code]
$.fn.dataTableExt.oApi.fnFilterAll = function(oSettings, sInput, iColumn, bEscapeRegex) {
for (var i in this.dataTableSettings) {
jQuery.fn.dataTableExt.iApiIndex = i;
this.fnFilter(sInput, iColumn, bEscapeRegex);
}
jQuery.fn.dataTableExt.iApiIndex = 0;
}
[/code]
If I don't do that, at some later point I get "Uncaught TypeError: Cannot read property 'aoData' of null" at some point after when I try to do something to the multitable selector for example: oTables.fnSort([]);

Just to explain what I'm doing that causes the above error:
1) I initialize one or more (up to 10) empty tables of the same type of data on a page.
2) Using ajax calls get data to populate the tables.
3) After each row is added I filter and sort the tables based on a series of checkbox filters.

I was using fnFilter on a $('.tableclass).dataTable() but realized that was only applying the filter to the first table. Changing to fnFilterAll started causing the page not to load past the first table with the above error. Resetting the iApiIndex seems to have fixed that.

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    I think that's a good point - otherwise the API index is left floating, which could be quite nasty. I've just added that into the plug-in code - thanks for flagging it up (and the fix!) :-)

    Regards,
    Allan
  • cdrwf150cdrwf150 Posts: 6Questions: 0Answers: 0
    No problem. Would I need a similar plugin for fnSort and fnSetColumnVis?
  • cdrwf150cdrwf150 Posts: 6Questions: 0Answers: 0
    edited February 2011
    I have added the following plugins to my code and they seem to have done the trick to sort only the visible nodes on multiple tables with one selector.
    [code]
    $.fn.dataTableExt.oApi.fnSortAll = function(oSettings, sInput) {
    for (var i in this.dataTableSettings) {
    jQuery.fn.dataTableExt.iApiIndex = i;
    this.fnSort(sInput);
    }
    jQuery.fn.dataTableExt.iApiIndex = 0;
    }
    [/code]
    and
    [code]
    $.fn.dataTableExt.oApi.fnSetColumnVisAll = function(oSettings, iColumn, bVisible) {
    for (var i in this.dataTableSettings) {
    jQuery.fn.dataTableExt.iApiIndex = i;
    this.fnSetColumnVis(iColumn,bVisible);
    }
    jQuery.fn.dataTableExt.iApiIndex = 0;
    }
    [/code]
This discussion has been closed.