I am new to angular js and have a basic understanding of how filters work in angular js. I am stuck with sorting my jSON data array, as there are various options by which it should be sorted.
My JSON array is in this format:
[ { type:0, emp_name:"xyz", connected_on:"9876543210" }, { type:1, emp_name:"", connected_on:"9876543210" }, { type:1, emp_name:"abcd", connected_on:"9876543210" }, { type:0, emp_name:"pqr", connected_on:"9876543210" } ]
Another combination of the same array may be:
[ { type:0, emp_name:"", connected_on:"9876543210" }, { type:1, emp_name:"xyz", connected_on:"9876543210" }, { type:0, emp_name:"abcd", connected_on:"9876543210" } ]
Each array will have one object, where type: 1 , will be there, and after sorting it should always be the first element.
After that, the sorted array should have all those elements that have emp_name: "" .
Finally, the sorted array should contain all other elements sorted according to emp_name: "any names"
Thus, the results should look something like this:
[ { type:1, emp_name:"xyz", connected_on:"9876543210" }, { type:0, emp_name:"", connected_on:"9876543210" }, { type:0, emp_name:"abcd", connected_on:"9876543210" } ]
Can someone help me write a filter to get the desired result. Thanks in advance. If any other information is required, please let me know.
Also connected_on is a unique value, so I use the track from JSONarr.connected_on