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

issue with null to filter in ng-grid.

Open csgopala opened this issue 12 years ago • 7 comments

Hi,

I want to filter the rows in a ng-grid table which has a column with null value. what should be my textString for the same ?

$scope.filterOptions = { filterText: "" };

$scope.gridOptions = { data: 'ctrl.titles', filterOptions: $scope.filterOptions }

$scope.filterOptions.filterText = ":^null";

I am not able to get the rows which has null for a certain field.

Thanks in advance for helping out with this issue.

csgopala avatar Sep 30 '14 18:09 csgopala

Which grid version are you using?

PaulL1 avatar Sep 30 '14 20:09 PaulL1

No response for over 2 weeks, assuming resolved.

PaulL1 avatar Oct 16 '14 02:10 PaulL1

I am sorry i was sick so could not access mails. i am using ng-grid 2.0.7 Currently i did work around instead of null i used value 'NONE' is it possible to filter on null?

csgopala avatar Oct 16 '14 20:10 csgopala

OK, I'm pretty sure that 2.x doesn't allow null filtering (and not sure that 3.0 does either).

PaulL1 avatar Oct 16 '14 20:10 PaulL1

ok. Thanks.

csgopala avatar Oct 17 '14 15:10 csgopala

Hi is 3.0 support null filtering on columns?

summer-liu avatar Jan 23 '15 03:01 summer-liu

Had a requirement to filter on blank data this past week and kept hitting this page on Google. So here's my solution.

In 3.0, there's support for adding dropdown filters. Simply create a dropdown filter with two conditions: populated and not populated. The default "blank" term will disable the filter. The following code creates the default contains filter and then the dropdown filter under that

var columnDef = [{
field: 'requestor.name',
          name: 'Requestor',
          filters: getFilterArrayWithNullFilter(uiGridConstants, 'Requestor'),
}];
  function getFilterArrayWithNullFilter(uiGridConstants, colName) {
    return [getContainsFilter(uiGridConstants), getNullFilter(uiGridConstants, colName)];
  }

  function getNullFilter(uiGridConstants, colName) {
    return {
      filterName: "nullFilter",
      type: uiGridConstants.filter.SELECT,
      selectOptions: [{value: 1, label: 'Has ' + colName}, {value: 2, label: 'No ' + colName + ' Specified'}],
      condition: function (searchTerm, cellValue) {
        return searchTerm == 0 || searchTerm == null || (searchTerm == 1 && cellValue != null) || (searchTerm == 2 && cellValue == null);
      }
    };
  }

  function getContainsFilter(uiGridConstants) {
    return {
      filterName: "containsFilter",
      condition: uiGridConstants.filter.CONTAINS,
      placeholder: "Contains"
    };

lethargicgeek avatar Mar 23 '16 05:03 lethargicgeek