Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groupBy then orderBy #207

Open
shahriarhossain opened this issue Jun 24, 2016 · 3 comments
Open

groupBy then orderBy #207

shahriarhossain opened this issue Jun 24, 2016 · 3 comments

Comments

@shahriarhossain
Copy link

shahriarhossain commented Jun 24, 2016

I am using the groupBy filter, after groupBy filtering I would love to do orderBy filtering.
I have tried orderBy after the groupBy clause but that didn't work.

Can you extend your groupBy example(https://github.com/a8m/angular-filter#groupby) with the orderBy functionality.

My scenerio:
$scope.browsers = [
{UniquePageviews: 500, Browser: 'chrome'},
{UniquePageviews: 700, Browser: 'chrome'},
{UniquePageviews: 200, Browser: 'firefox'},
{UniquePageviews: 100, Browser: 'safari'},
{UniquePageviews: 250, Browser: 'safari'},
{UniquePageviews: 50, Browser: 'safari'},
{UniquePageviews: 0, Browser: 'opera'},
{UniquePageviews: 0, Browser: 'opera'},
{UniquePageviews: 1000, Browser: 'IE'},
{UniquePageviews: 800, Browser: 'IE'},
];

$scope.totalBrowserCount = function () {
var total = 0;
for (var i = 0; i < data.length; i++) {
var product = data[i].UniquePageviews;
total += product;
}
return total;
}

{{key}} {{(value | map: 'UniquePageviews' | sum) * 100 / totalBrowserCount() | number :0}}%

Above code groups the result and in the list it only shows each browser name. But as you can see few browsers have most unique visits (i.e. IE has 1800 in total), so I am expecting IE on the top of the list.

@mjortman
Copy link

mjortman commented Jan 9, 2017

Did you ever find an answer? I'm having difficulty with this as well. I've moved the orderBy around both before and after the groupBy, I tried using toArray as in the example, and none of it seems to work.

@a8m
Copy link
Owner

a8m commented Jan 9, 2017

Hi @mjortman, did you see this example?
Can you share a jsbin example with us?

Thanks

@onigetoc
Copy link

onigetoc commented Apr 9, 2017

I think this filter module should handle all common function like orderBy, sort ect.
Without manipuling ourself the javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants