对于AngularJS ui-grid 3.x我定义了一个过滤器对象来过滤空值:
$scope.gridOptions = {
enableFiltering: true,
columnDefs: [
{ field: 'assignedto',
name: 'Assigned To',
width: 250,
filter: ... the filter object ..
}]
过滤器对象如下所示:
{
filter: {
type: uiGridConstants.filter.SELECT,
selectOptions: [{ value: 1, label: 'Defined' },
{ value: 2, label: '(Blanks)' }],
condition: function (searchTerm, cellValue) {
return
searchTerm == 0 ||
searchTerm == null ||
(searchTerm == 1 && cellValue != null) ||
(searchTerm == 2 && cellValue == null)
}
}
此过滤器对象提供了一个Dropbox。使用下拉框,应该过滤包含空值的行。但是过滤器不起作用,我认为它与未正确设置的条件有关。如何设置它以使其工作?
一些初始数据,我想过滤列'assignedto'包含空值的行:
$scope.gridOptions = {
data: [
{ assignedto: 'James' },
{ assignedto: 'Nicole' },
{ assignedto: '' },
{ assignedto: 'James' },
{ assignedto: 'Nicole' },
{ assignedto: '' }
]
};