ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Custom cellFilter and 'getRowVisibility' used in 'onFilterChanged' not returning correct rows

Open Nightmaster opened this issue 11 years ago • 4 comments

I have find a problem. If you apply a custom cell-filter to a column, and then you use the gridApi.core.on.filterChanged function to call a function wich calls gridApi.core.getVisibleRows(), the returned rows by the getVisibleRows are the one visible before the filter was applied and the function do not have any argument.

I have done a Plunker (based on ui-grid.info/docs/#/tutorial/103_filtering page) to show what I mean http://embed.plnkr.co/52wNFcQtA6ACuXkHP8Yy/preview

Nightmaster avatar Aug 07 '15 15:08 Nightmaster

I have the same problem.

gridApi.core.on.filterChanged($scope, function () {
  // here rows returned are not for current filter but for previous filter
  var rows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
});

My filter condition is:

            filter: {
              condition: function (searchTerm, cellValue) {
                return cellValue.fio().toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1;
              }//uiGridConstants.filter.CONTAINS
            }

Each time filterChanged fired, getVisibleRows returns not new visible (filtered) rows but rows before new filter is applied.

Currently I find a workaround - run getVisibleRows from filterChanged in $timeout after 100ms.

gridApi.core.on.filterChanged($scope, function () {
  $timeout(function () {
    // here rows returned are for current filter
    var rows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
  }, 0);
});

But I worry that it is not correct as based on assumption that 100ms is enought. But in some cases it can be not.

xak2000 avatar Sep 04 '15 15:09 xak2000

I tried to use gridApi.core.on.rowsVisibleChanged event with better results. It doesn't work without timeout but at least it consistently work with timeout 0.

        gridApi.core.on.rowsVisibleChanged($scope, function () {
          // still doesn't work
          var rows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
        });
        gridApi.core.on.rowsVisibleChanged($scope, function () {
          // does work!
          $timeout(function () {
            var rows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
          }, 0);
        });

But there are another problem: rowsVisibleChanged is not fired after filter is cleared! I think it is also a bug. See #3901.

xak2000 avatar Sep 04 '15 16:09 xak2000

Lastly I make it to work using rowsRendered event.

        gridApi.core.on.rowsRendered($scope, function () {
          // does work!
          var rows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
        });

But I think bugs explained in this issue are still valid. filterChanged and rowsVisibleChanged must work too.

xak2000 avatar Sep 04 '15 16:09 xak2000

merged PR to fix this v3.2.10

dlgski avatar Sep 20 '16 18:09 dlgski