Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For SELECT filter ng-options, use track by instead of selectAs #3408

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/js/core/services/rowSearcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
}

var term = rowSearcher.getTerm(filter);

// A searchOption value could be an object so it is better to user angular.equals instead of a regex.
if (angular.isObject(term) && term.value && !angular.isDefined(filter.condition)) {
return function(searchTerm, cellValue) {
return angular.equals(searchTerm, cellValue);
};
}

if (/\*/.test(term)) {
var regexpFlags = '';
Expand Down Expand Up @@ -178,7 +185,8 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
var conditionType = typeof(filter.condition);

// Term to search for.
var term = filter.term;
// Exctract the term.value for selectOptions since ng-options track by returns the entire object.
var term = angular.isObject(filter.term) && filter.term.value ? filter.term.value : filter.term;

// Get the column value for this row
var value = grid.getCellValue(row, column);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/ui-grid/ui-grid-filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>

<div ng-if="colFilter.type === 'select'">
<select class="ui-grid-filter-select" ng-model="colFilter.term" ng-attr-placeholder="{{colFilter.placeholder || ''}}" ng-options="option.value as option.label for option in colFilter.selectOptions">
<select class="ui-grid-filter-select" ng-model="colFilter.term" ng-attr-placeholder="{{colFilter.placeholder || ''}}" ng-options="option.label for option in colFilter.selectOptions track by option.label">
<option value=""></option>
</select>

Expand Down