<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" id="ng-app" ng-app="spike">
<head>
    <!--
        This page can be used as a base for spiking with jQuery, AngularJS and Kendo.
        All scripts and styles are loaded from a CDN or inline.
    -->
    <title>Spike page</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"><!-- Use highest support for modern standards . -->
    <!-- Library styles -->
    <link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.silver.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.silver.mobile.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.dataviz.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.dataviz.silver.min.css" rel="stylesheet" />
    
    <!-- Library scripts -->
    <script src="http://cdn.kendostatic.com/2014.2.1008/js/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.2.1008/js/kendo.all.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.2.1008/js/cultures/kendo.culture.nl-NL.min.js"></script>
    
    <!-- App styles -->
    <style>
        /*
            A small custom reset stylesheet is used, to fix style differences between browsers.
        */
        html, body {
            height: 100%; /* App layout uses a 100% height layout. */
        }

        body, div, input, li, p, select, ul {
            border: 0; /* Remove unwanted space. */
            -webkit-box-sizing: border-box; /* Place the border and padding inside the box. */
            -moz-box-sizing: border-box; /* Place the border and padding inside the box. */
            -ms-box-sizing: border-box; /* Place the border and padding inside the box. */
            -o-box-sizing: border-box; /* Place the border and padding inside the box. */
            box-sizing: border-box; /* Place the border and padding inside the box. */
            font-family: "Open Sans", sans-serif;
            font-size: 15px;
            margin: 0; /* Remove unwanted space. */
            outline: 0; /* Remove unwanted space. */
            padding: 0; /* Remove unwanted space. */
        }

        body {
            padding: 20px; /* Create space between browser border and content. */
            min-width: 320px; /* App will not work beneath width: 320px. */
        }
    </style>

    <!-- App scripts -->
    <script>

        (function () {
            "use strict";

            // This is the starting point (main) for the angular app.
            var app = angular.module("spike", ["kendo.directives"]);

            // Set culture info to Ducth:
            kendo.culture("nl-NL");
        }());
   
        (function () {
            "use strict";

            var app = angular.module("spike");

            var controller = function ($scope, $animate) {
                $scope.title = "Programmatically set kendo grid total pageSize, when using Angular.";
                
                var data = [
                    { id: 1, name: "Bob1" },
                    { id: 2, name: "Bob2" },
                    { id: 3, name: "Bob3" },
                    { id: 4, name: "Bob4" },
                    { id: 5, name: "Bob5" },
                    { id: 6, name: "Bob6" },
                    { id: 7, name: "Bob7" },
                    { id: 8, name: "Bob8" },
                    { id: 9, name: "Bob9" },
                    { id: 10, name: "Bob10" },
                    { id: 11, name: "Bob11" },
                    { id: 12, name: "Bob12" }
                ]


                $scope.mainGridOptions = {
                    dataSource: {
                        data: data,
                        pageSize: 4
                    },
                    pageable: {
                        pageSizes: [4, 8, 12]
                    },
                    sortable: true,
                    dataBinding: function (e) {
                        // This is a fix.
                        // When the user selects an other page size in the "page size" dropdownlist, 
                        // the MainGridOptions are not updated.
                        // To reflect the changes from the "page size" dropdownlist, we set the "page size" manually here.
                        $scope.mainGridOptions.dataSource.pageSize = e.sender.dataSource.pageSize();
                    }
                };

                $scope.setPageSize = function () {
                    $scope.mainGridOptions.dataSource.pageSize = data.length;
                };
            };

            app.controller("main", ["$scope", controller]);
        }());
    </script>
</head>
<body>
    <div ng-controller="main">
        <h2>{{ title }}</h2>
        <div>
            <br />
            <button ng-click="setPageSize()">Set page size</button>
            <br />
            <br />
            <div kendo-grid="mainGrid"
                 k-options="mainGridOptions"
                 k-rebind="mainGridOptions"></div>
        </div>
    </div>
</body>
</html>

// Code goes here

/* Styles go here */