AngularJS orderBy not working - angularjs

i am facing some weird issue in ordeBy, i know this should be very simple but couldn't make out
Please look at a below plunker, where the orderBy by value not showing correct output, i don't no why :(
DEMO PLUNKER

If you want to keep doing that, you'll have to create a filter for inverted indexes based on the property you want (here the whole object) so that you can retrieve the key and hence the value

You will have to convert the numbers to strings and make sure the strings are the same length
var temp = {"054": "A",
"244": "B",
"344": "C"};
this works.

Related

Filter array by variable in Bot Framework .net

For each item in array1, I want to filter array2 by the array1 item the bot is currently in.
Within an Edit an array property, if I filter array2 hard-coded like so it creates a nice array:
"changeType": "push",
"itemsProperty": "user.array2",
"value": "=where(json(user.apiResponse.content).value,x,x.myKey=='magazine')"
However if I use a dynamic key based on the current item in array1, this doesn't work:
"changeType": "push",
"itemsProperty": "user.array2",
"value":"=where(json(user.apiResponse.content).value,x,x.myKey==concat('\'',json(dialog.forEachThing.value).name,'\''))
I've tried setting a property, user.myFilter and passing that, as below.
"property": "user.myFilter",
"value": "=concat('\\'',json(dialog.forEachThing.value).name,'\\'')"
And while this user.myFilter evaluates correctly to 'magazine', the Edit an array property/push doesn't get any values.
I'd really welcome any thoughts on where I'm going wrong. I've tried a few things like '''' in user.myFilter but these evaluate as null.
Ok, updated answer here for those who follow.
Turns out I was wrong. In .Net anyway, the solution is to simply not wrap the variable in single quotes. Thanks to Dana V in github for the heads up.
It seems that may not work in Javascript however.

Angularjs - How to filter objects by multiple values in their properties

I am having different objects like in the code sample below. I have some checkboxes that filters based on brewer, style, aroma and country. It is filtering only if it has one property in the array.
What is the best solution to make the filter work based on all the elements in the array? I checked some other questions and I couldn't find anything related.
It will be great if any of you could help me.
Thanks.
sample of the code here: http://pastie.org/10787362
You could use filter method of Javascript Array() object.
For example:
$scope.filteredNames = $scope.names.filter(function(element) {
return
'brewer1' in element.brewers &&
'aroma1' in element.aromas
;
});
$scope.filteredNames should contain all names with 'brewer1' value in brewers property AND 'aroma1' value in aromas property...

How to check duplicate values in more then one rows in Angular ui-grid.

I am beginner in of AngularJS therefore I have a simple question.
Is there any method provided or sample code in ui-grid to check the duplicate values in more then one rows in ui-grid.?
i want to color the cell where duplicate value exist.
There is no TRUE built-in way, however using $watch is one solution. If values in your ui-grid are bound to a variable called myGridVals, you would do something like this:
$scope.$watch('myGridVals',function(newval,oldval) {
// loop through myGridVals and see if newval matches anything
});
Note that if your array holds objects you'll want to do a DEEP watch which means adding a third param to $watch(..,..,true);
You can also

applying class in ng-repeat if contained in another array

I am querying for a collection of IDs from Parse.com and showing them in my $scope as an array.
I would like to apply a class to the items in my $scope that match any one of these IDs, placing a border around the object illustrating that it is already contained in the 'saved' array. I have tried the following however not having any luck.
ng-class="{'approved': ParseSavedExercises.indexOf(exercise.id) == -1}"
in this case my ParseSavedExercisesis my array to check against and exercise.id is what I am checking for.
here is a quick fiddle
Please see here http://jsfiddle.net/e9pr4yqj/
Yours ParseSavedExercises contains string and id is number so no id existed in ParseSavedExercises
$scope.ParseSavedExercises = ['2','3'];
change to
$scope.ParseSavedExercises = [2,3];
or use
ng-class="{'approved': ParseSavedExercises.indexOf(exercise.id.toString()) == -1}"
like here http://jsfiddle.net/1ujgvL80/

filter list with multiple checkboxes in Angularjs

I would like to filter a ng-repeat list of items with multiple catgories checkboxes.
i read this Filtering by multiple checkboxes in AngularJS and watched the videos by Egghead, but i have an error on a simple for loop and i don't understand:
ReferenceError: i is not defined
here is a plunker with the code : http://plnkr.co/edit/p538ALfs00JTFQ6mKT9j
thank you for your help
If you're going to use strict mode ('use strict';), you need to declare your variables. Your checkboxFilter uses many variables that are never defined (i included). You can get past the your initial issues by changing script.js:22-23 to:
var i,j,k,filter_cat,filter_value,filter_name,matchingItems = [];
You have three other problems after that...
Line 37, This code is looking for a property named filter_cat: items[i].filter_cat, when what you wanted was to look for a property name with the value of filter_cat, so this is what you want: items[i].[filter_cat].
Your json data has lowercase field names and your code is searching on uppercase (Type vs type)
Your json data has lowercase values and your code is searching on uppercase (Fruit vs fruit)
Here is a partial edit that gets you on the right track. You'll still need to modify your json or compare lowercase (I partially modified your json): http://plnkr.co/edit/d7p4QthXJg4ao34ATWla?p=preview

Resources