3

Developing my app I encountered with a problem, I have a filter in my ng-repeat. I can search by productCode or name. After that appears a new requirement "Filter by SubcategoryId".

The product is associated to a subcategory but I have the problem to filter exactly only by subCategoryId strictly and the productCode or name with proximity search.

Result:

Filtering by subCategoryId = 1

Only I want to show subCategoryId products but it brings a product list with SubcategoryId = 1, 11, 111 etc..

It's there a way to filter exactly by subCategoryId and the name, codigoProducto with proximity?

Filters Layout

 <input placeholder="PALABRA CLAVE" type="text" ng-model="filtros.name"  ng-change="changeCurrentPage(0);" />
 <input placeholder="CODIGO PRODUCTO" type="text" ng-model="filtros.codigoProducto"  ng-change="changeCurrentPage(0);"/>
 <select ng-model="filtros.subCategoryId" ng-change="changeCurrentPage(0)">
     <option  value="">TODOS</option>
     <option ng-repeat="subct in subCategories" value="{[{subct.id}]}"{[{subct.name}]}</option>
</select>

List.

<li ng-animate="'animate'" ng-repeat="prod in objtemp.products | orderBy:'ordenProducto' | filter:filtros | startFrom:currentPage*pageSize:this | limitTo:pageSize" ng-class='{marginLeftNone: $index%4==0}' >

Sorry for my bad English.

Thank you so much if You can help me.

Post Edited.

This is the jsfiddle.

http://jsfiddle.net/schwertfische/2aW7Q/34/

Amir
  • 1,328
  • 2
  • 13
  • 27
schwertfisch
  • 4,549
  • 1
  • 19
  • 32
  • @Yoshi thank you for your quick answer, I have tried with this but not lucky, filter:filtros:true, it applys to filtros.name and filtros.codigoProducto also, and it should be only for filtros.subCategoryId – schwertfisch Dec 13 '13 at 19:51
  • if I understand correctly `filter:filtros:true` should do exact match – Bro Dec 13 '13 at 19:51
  • http://plnkr.co/edit/nDa1cIt2e0Ej8cvv4pYe?p=preview from http://stackoverflow.com/questions/18242520/exact-filter-in-angular – Bro Dec 13 '13 at 20:04
  • @Yoshi Sorry, not working =(, It's not listing the products. I'm going to try Bro Solution. – schwertfisch Dec 13 '13 at 20:14
  • @Schwertfisch would you mind setting ab a [jsfiddle](http://jsfiddle.net) or other. Your code is kind of hard to follow. – Yoshi Dec 13 '13 at 20:17
  • @Yoshi, I'm going to try but It's conneted to a Resfult service, this is the testing host. http://plastimex.lapreca.com/catalogo/hogar – schwertfisch Dec 13 '13 at 20:24
  • @Schwertfisch just fake the data with some samples, it's really not that important. The filter will work just the same. – Yoshi Dec 13 '13 at 20:25
  • @Yoshi Working in that. – schwertfisch Dec 13 '13 at 20:42
  • http://plnkr.co/edit/xsP9RfpkWs6hRbL8dq0X?p=preview this one does exact and approximate it could probably be cleaned up a bit – Bro Dec 13 '13 at 20:43
  • Starting in 1.0.3 the exact match functionality is built in without a custom filter. – Bro Dec 13 '13 at 20:55
  • @Bro Also I'm trying with your solution and no luck, I'm setting example on jsfiddle, maybe more easy. thank you so much – schwertfisch Dec 13 '13 at 21:14
  • @Yoshi and Bro, this is the jsfiddle, the problem occurs when the selection is id 1-basureros because it brings subcategory productos 11 also, You can see it on page 3 http://jsfiddle.net/schwertfische/2aW7Q/34/ – schwertfisch Dec 13 '13 at 23:24
  • @Schwertfisch The first problem I see is that you want to mix exact and non exact filtering (only one `filtros` object). Which will not work. You could split the filter expression to not include the `subCategoryId` and use two filters: `| filter:filtros | filter:{ subCategoryId: bySubCategoryId }:true`. Though this will then fail, because you're building the select with `ng-repeat` which will result the model value to allways be a string. Which of course won't work for strict comparsion when the subCategoryIds are all ints. Personally, and seeing that you're reusing the same logic multiple... – Yoshi Dec 14 '13 at 09:47
  • @Schwertfisch ... times (for the paging component), I think it's your best bet to extract to filter logic and build your own custom filter. This way the view code will get easier to read. And you can compensate for the above mentioned problems. I'll try to add an example, though this could take a while. – Yoshi Dec 14 '13 at 09:48

2 Answers2

1

The model has changed so now it's working. Thank You everybody for your help, Also I updated jsfiddle because it's a helpful source and You can rework.

..... var myApp = angular.module('myApp',[]); .....

JsFiddle

....

schwertfisch
  • 4,549
  • 1
  • 19
  • 32
0
<ul><li ng-repeat="item in model.data | filter: { subCategoryId: filtros.subCategoryId }">{{item.title}}</li>

it's example for your filter

KoIIIeY
  • 533
  • 1
  • 7
  • 26