issue with null to filter in ng-grid.
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.
Which grid version are you using?
No response for over 2 weeks, assuming resolved.
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?
OK, I'm pretty sure that 2.x doesn't allow null filtering (and not sure that 3.0 does either).
ok. Thanks.
Hi is 3.0 support null filtering on columns?
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"
};