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

Grouped ListLayout - how? #35

Closed
JimSEOW opened this issue May 31, 2015 · 2 comments
Closed

Grouped ListLayout - how? #35

JimSEOW opened this issue May 31, 2015 · 2 comments
Assignees
Milestone

Comments

@JimSEOW
Copy link

JimSEOW commented May 31, 2015

http://try.buildwinjs.com/#listview:grouped

var myData = new WinJS.Binding.List([
        { title: "Banana Blast", ...

]};

var grouped = myData.createGrouped(function (item) {
    return item.title.toUpperCase().charAt(0);
}, function (item) {
    return {
        title: item.title.toUpperCase().charAt(0)
    };
}, function (left, right) {
    return left.charCodeAt(0) - right.charCodeAt(0);
});

How to implement that in angularjs e.g.

$scope.items = [
 { title: "Banana Blast", ...

];

$scope.grouped  = 
@JimSEOW
Copy link
Author

JimSEOW commented May 31, 2015

I would like to know if it is possible and in the case how we can use listview:grouped ( http://try.buildwinjs.com/#listview:grouped ) with angular-winjs. Thanks.

@TheWrathOfConst
Copy link
Collaborator

Yep, it's possible to use grouped ListViews. You need to have an Binding.List set up on your scope that supports grouping. Here's an example:

<!DOCTYPE html>
<html ng-app="sample" ng-controller="sampleController">
<head>
    <title>Example of Grouped ListView</title>
    <link rel="stylesheet" type="text/css" href="Microsoft.WinJS.4.0\css\ui-dark.css" />
    <script type="text/javascript" src="Microsoft.WinJS.4.0\js\base.js"></script>
    <script type="text/javascript" src="Microsoft.WinJS.4.0\js\ui.js"></script>
    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="angular-winjs.js"></script>
    <script>
        angular.module('sample', ['winjs']).controller("sampleController", function ($scope) {
            $scope.dataSource = new WinJS.Binding.List([1, 2, 3, 4, 5]).createGrouped(function groupingFunction(item) {
                if (item < 3) {
                    return "0";
                }
                return "1";
            }, function groupData(item) {
                if (item < 3) {
                    return {title: "Group 0"};
                }
                return { title: "Group 1" };
            });
        });
    </script>
</head>

<body>
    <win-list-view item-data-source="dataSource" group-data-source="dataSource.groups">
        <win-item-template>
            Item {{item.data}}
        </win-item-template>
        <win-group-header-template>
            {{item.data.title}}
        </win-group-header-template>
    </win-list-view>
</body>

</html>

@jdalton jdalton closed this as completed Jul 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants