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

Cell with filter type SELECT not matching by EXACT condition

Open gfutac opened this issue 10 years ago • 5 comments

Hi,

I've noticed that when you change columnDefs of a grid after they were initially created (in order to dynamically populate selectOptions of a cell that has filter type set to uiGridConstants.filter.SELECT) filter's condition will not be applied - grid will "guess" and set condition to CONTAINS.

Example scenario (like in provided plunker):

  1. define columnDefs
  2. fetch info about columns that has to be filtered as a uiGridConstants.filter.SELECT` (from a service or so)
  3. update column definition of a desired columns (set cellFilter and define filter object) 3.1. eg. define selectOptions to have values 1, 2, 12
  4. update columnDefs by calling $scope.gridOptions.columnDefs = angular.copy($scope.gridOptions.columnDefs);
  5. load grid data

Result - when you try to filter by either 1 or 2, results with values {1, 12} and {2, 12} will appear among visible rows.

Note - specifying condition: uiGridConstants.filter.EXACT does not work (as stated above), but doing something like $scope.gridApi.grid.columns[columnIndex].filters[0].condition = uiGridConstants.filter.EXACT; will do the job, but I find it hacky.

Shouldn't cell of type uiGridConstants.filter.SELECT always be filtered with condition se to uiGridConstants.filter.EXACT ?

gfutac avatar Nov 24 '16 10:11 gfutac

+1 This should be the expected behavior for select filters.

Andyvec avatar Mar 03 '17 17:03 Andyvec

Thanks for this workaround: $scope.gridApi.grid.columns[columnIndex].filters[0].condition = uiGridConstants.filter.EXACT; saved me a lot of time!

apodznoev avatar Mar 09 '17 11:03 apodznoev

Hi apodznoev,

$scope.gridApi.grid.columns[columnIndex].filters[0].condition = uiGridConstants.filter.EXACT;

where to exactly put this code, I'm sorry if the question is too stupid, I'm new to this technology, thanks in advance

ruhaise avatar Nov 15 '17 09:11 ruhaise

why is this closed? Did it get solved? I'm running into this (version 3.2.1) and I'm not sure wether I should upgrade.

molecular avatar Jan 15 '20 08:01 molecular

I'm confused now. I fixed this for me by adding the condition line in my column definition

{ field: 'art.id',
					displayName: 'Art',
					width: '70',
					enableFiltering: true,
					filter: {
						type: uiGridConstants.filter.SELECT,
						condition: uiGridConstants.filter.EXACT,
						selectOptions: this.BeitragsArten
					},
					cellTemplate: '<div class="ui-grid-cell-contents">{{ row.entity.art.name }}</div>',
					enableCellEdit: false,
				},

molecular avatar Jan 15 '20 08:01 molecular