filterBy(0,function(val,rowId){... iterates on old rowid's

Hi,

When using grid.filterBy(0,function(val,rowId){}) after having done a grid.clearAndLoad just before, the filterBy seems to iterate the grid using old rowIds from the previous listing in it and getting error “Cannot read property ‘_childindexes’ of null” a lot.

I noticed the error only occurs if you have already performed filterBy() on the populated grid and then reloaded (using clearAndLoad(), but also tried adding grid.clearAll() with the same result) with a smaller set.

The stacktrace:

Uncaught TypeError: Cannot read property '_childIndexes' of null dhtmlx.js:875 dhtmlXGridObject.cells dhtmlx.js:875 multiSearch tab_attest_single.jsp:1201 (anonymous function) tab_attest_single.jsp:1192 dhtmlXGridObject._filterA dhtmlx.js:963 dhtmlXGridObject.filterBy dhtmlx.js:962 filterGrid tab_attest_single.jsp:1190

Non-working code:

grid.filterBy(1, function(val,rowId){ return multiSearch(rowId,s.toUpperCase()); });

To get it working, I hade to change it to:

grid.filterBy(1, function(val,rowId){ return grid.doesRowExist(rowId) && multiSearch(rowId,s.toUpperCase()); });

Function multiSearch, for reference:

function multiSearch(rowId,s){ // search against column 2 if (grid.cells(rowId,1)!=null && grid.cells(rowId,1).getValue().toUpperCase().indexOf(s)> -1){ return true; } // search against column 3 else if (grid.cells(rowId,2)!=null && grid.cells(rowId,2).getValue().toUpperCase().indexOf(s)> -1){ return true; } // search against column 4 else if (grid.cells(rowId,3)!=null && grid.cells(rowId,3).getValue().toUpperCase().indexOf(s)> -1){ return true; } // search against column 7 else if (grid.cells(rowId,6)!=null && grid.cells(rowId,6).getValue().indexOf(s)> -1){ return true; } // search against column 8 else if (grid.cells(rowId,7)!=null && grid.cells(rowId,7).getValue().toUpperCase().indexOf(s)> -1){ return true; } // search notes in userdata else if (grid.getUserData(rowId,'notes') != null && grid.getUserData(rowId,'notes').toUpperCase().indexOf(s)> -1){ return true; } else{ return false; } }

Could you please look into that?

Regards,
Johnny

PS. Guessing it is due to old rowids in some grid internal rowbuffer probably?
Adding this snippet before my grid.clearAndLoad(…) of course fixes the issue, but I’d like to keep to documented API calls, if possible.

grid._f_rowsBuffer = null;

PS2. This is somewhat related to my request here: viewtopic.php?f=2&t=38128 DS.

Unfortunately it is not recommended to change grid’s data in the filtered state.
You need to:

  1. Unfilter the grid;
  2. Add/remove the desired rows;
  3. Filter the grid back.
    docs.dhtmlx.com/grid__filtering. … lteredgrid

Nope, that’s not it.

The error occurs regardless of whether the grid is in filtered state or not when doing the clearAndLoad and then a new filterBy (on a data set smaller than tan the previously loaded, as described earlier).
I just verified this by adding “grid.filterBy(0,’’);” just before my clearAndLoad.

I stand by my hypothesis that to behave as would be expected the clearAndLoad needs to be enhanced to clear the interal row buffer of the grid in some way (although I see your linked doc page now recommends clearing the row buffer after un-filtering the grid).

Thanks,
Johnny

you’re right.
in case rebuilding the data for the grid you need to clear the cache of the filters.
grid._f_rowsBuffer = null;