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

Custom Filter is broken

Open miah-al opened this issue 11 years ago • 6 comments

http://ui-grid.info/docs/#/tutorial/103_filtering

Steps to reproduce

  1. Put some values in the age column filter (both greater than and smaller than)
  2. Delete the contents of the filter
  3. Put some filters again.

miah-al avatar Jul 02 '15 20:07 miah-al

When I do that it seems to work fine. What behaviour do you get when you put the filters back in?

PaulL1 avatar Jul 02 '15 20:07 PaulL1

When I put the filter back in the grid shows nothing. Try using backspace instead of the x button.

miah-al avatar Jul 02 '15 22:07 miah-al

I followed your steps and experienced the same problem.

JLLeitschuh avatar Jul 03 '15 00:07 JLLeitschuh

Making a small change to searchColumn function fixes the issue

 rowSearcher.searchColumn = function searchColumn(grid, row, column, filters) {
    if (grid.options.useExternalFiltering) {
      return true;
    }

    var filtersLength = filters.length;
    for (var i = 0; i < filtersLength; i++) {
      var filter = filters[i];

      if ( !gridUtil.isNullOrUndefined(filter.term) && filter.term !== '' || filter.noTerm ){

          var ret = rowSearcher.runColumnFilter(grid, row, column, filter);
          if (!ret) {
            return false;
          }
        }
    }


    return true;
  };

The issue is only for columns with multiple filters(for age column it is greater than and less than). runColumnFilter should not get called with empty filters.

miah-al avatar Jul 04 '15 23:07 miah-al

If you think you've solved the issue feel free to make a pull request and we'll review it.

JLLeitschuh avatar Jul 06 '15 16:07 JLLeitschuh

If anyone looking for a temporary fix

var uiGridCustom = {
    filter: {
        GREATER_THAN: function (searchTerm, cellValue) {
            if (searchTerm == '')
                return true;
            else return cellValue > searchTerm;
        },
        LESS_THAN: function (searchTerm, cellValue) {
            if (searchTerm == '')
                return true;
            else return cellValue < searchTerm;
        }
    }
};

balakrishnangithub avatar Dec 17 '15 07:12 balakrishnangithub