1

In my angularjs app I'm using UI select.This is my Html

<ui-select name="service" multiple ng-model="service.ServiceName" close-on-select="false" >
                <ui-select-match placeholder="Select Services...">{{$item.ServiceName}}</ui-select-match>
                <ui-select-choices repeat="service in Services | filter: {ServiceName: $select.search} | filter:myFilter track by service.ServiceId">
                      {{service.ServiceName}}
                </ui-select-choices>

Select filter provides contains search but I want to filter elements on the basis of StartsWith.I have seen a couple of examples of startswith filter but I'm unable to incorporate them in UI Select.

4
  • please also post the code of your filter Commented May 1, 2016 at 19:42
  • And no one of startswith filters that you found isn't working? Did you try something like that ? Commented May 1, 2016 at 19:59
  • @MAkCblMKo I have tried that and put a debug point in the startswith function but it never hits the debug point. Commented May 1, 2016 at 20:14
  • @kabaehr filter: {ServiceName: $select.search} this is the default ui select filter which I'm using for search and myFilter is for excluding the selected services frmo the dropdownlist. Commented May 1, 2016 at 20:16

1 Answer 1

3

Single item : Plunker.

JS

vm.startsWith = function (actual, expected) {
    var lowerStr = (actual + "").toLowerCase();
    return lowerStr.indexOf(expected.toLowerCase()) === 0;
  }

Html

<ui-select-choices repeat="country in ctrl.countries|filter:$select.search:ctrl.startsWith">
      <span ng-bind-html="country.name | highlight: $select.search"></span>
      <small ng-bind-html="country.code | highlight: $select.search"></small>
    </ui-select-choices>

Multiple Items : Plunker

JS is same as the above.

Html

<ui-select multiple ng-model="ctrl.multipleDemo.colors" theme="bootstrap" ng-disabled="ctrl.disabled" close-on-select="false" style="width: 300px;" title="Choose a color">
    <ui-select-match placeholder="Select colors...">{{$item}}</ui-select-match>
    <ui-select-choices repeat="color in ctrl.availableColors | filter:$select.search : ctrl.startsWith">
      {{color}}
    </ui-select-choices>
  </ui-select>
Sign up to request clarification or add additional context in comments.

7 Comments

thanks Sapath but it did not work in my case.May be because I'm using mutiselect.
can you put the url of the angular module which you're using (mutiselect) ?
Sorry Sampath I could not understand you?
Which Api are you using for the above UI Select ? B'cos lot of apis are there for the same purpose. What did you mean by mutiselect ?
Then why my above example is not working for you ? I have used the same api for the above Plunker.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.