1

I have array of objects that holds two properties(title, params). When I apply following filter all values are searched for match.

The problem is that type.title value is not translated and I need to filter out array items which translated title property matches with the $select.search value

<ui-select-choices repeat="type in codeLists.reportTypes | filter: $select.search">
devqon
  • 13,818
  • 2
  • 30
  • 45
Zveratko
  • 2,663
  • 6
  • 35
  • 64
  • Then you probably should make a custom filter/search function – devqon Jan 27 '17 at 13:49
  • I don't want to add app wide filter for this, but I cannot understand the syntax of angular filter, which probably can be of some help. – Zveratko Jan 27 '17 at 13:51
  • 1
    How do you translate your stuff? What does your 'type.title' property look like? Do you use `ng-translate`? – devqon Jan 27 '17 at 13:52
  • I have seen [this]([http://stackoverflow.com/a/23569180/2944265]) which I completely doesn't have a clue how it works. I tried to use it, but with some nothing saying errors. – Zveratko Jan 27 '17 at 13:52
  • Title is "R1" and I will use 'docKey.' + type.title | translate – Zveratko Jan 27 '17 at 13:54

1 Answers1

2

You have two options for this:

1) Pre-translate all titles

$scope.cldeLists.reportTypes.forEach(function(item) {
    item.translatedTitle = $filter("translate")("docKey." + item.title);
});

Then you can use it in your filter:

<ui-select-choices repeat="type in codeLists.reportTypes | filter: { translatedTitle: $select.search }">

2) Create a custom filter which searches the translated item:

app.filter("translatedPropertyFilter", function($filter) {
    return function(item, property, searchString, prefix) {
        if (!prefix) prefix = "";            

        return $filter("translate")(prefix + item[property]).indexOf(searchString) > -1;
    }
});

Usage:

<ui-select-choices repeat="type in codeLists.reportTypes | translatedPropertyFilter:'title':$select.search:'docKey.'">
devqon
  • 13,818
  • 2
  • 30
  • 45
  • Do you understand the syntax from [here](http://stackoverflow.com/a/23569180/294426)? – Zveratko Jan 27 '17 at 14:23
  • Yes, but that is a plain `select`, you are using `angular-ui-select`, which has its own template for displaying options. So you cannot use that solution in this case. – devqon Jan 27 '17 at 14:30