axel-zarate / js-custom-select

Custom auto-complete select box for AngularJS and Bootstrap
MIT License
68 stars 59 forks source link

Applying custom filters #10

Closed santaux closed 8 years ago

santaux commented 9 years ago

Hi!

First of all, thank you for a good widget. You've done good job. I'm trying to find a way to use my own filters for ng-options/cs-options of the custom select. Currently, I need to remove from dropdown list elements from the array and do it dynamically.

For example, I need an parameter like

cs-exclude="arrayOfParamsToExclude"

or just:

cs-options="a.name for a in myArray | myOwnFilter"

How can I do it in best way?

axel-zarate commented 9 years ago

Hi, The custom-select directive relies on a filter filter internally. Filters can be chained together but right now the directive doesn't handle that well. Until a fix is found, the best thing you can do is perform the filtering in your controller and assign the result to the property you use for the ng-model.

$scope.originalArray = ...;
$scope.myArray = someFilter($scope.originalArray);
cs-options="a.name for a in myArray"
axel-zarate commented 9 years ago

Update: This issue is addressed in this new branch I just created. Note that breaking changes were introduced to simplify the control and move away from the approach that is causing other issues in newer versions of Angular.

You will be able to use custom-select="a.name for a in myArray | myOwnFilter: $searchTerm"

Or custom-select="a.name for a in myFunction($searchTerm)"

As soon as the version in this branch is stable, I will move it to the master branch.

Let me know how this works for you.

santaux commented 9 years ago

Oh, cool, thank you! I'll try to test it soon.