Domanda

I'm using the "kendo.web.min.js" to create a kendo grid through the scope, like that:

<div id="grid" kendoui-grid ng-model="rows"></div>
$("#grid").kendoGrid({....

And in the scope I get the element by its id and build the grid on it.

Now I need to use it as a directive, like that (without an id):

<div kendo-grid k-options="mainGridOptions"></div>

As shown here:

http://kendo-labs.github.io/angular-kendo/#/Grid

But the grid fails to show.

Is the "kendo.web.min.js" the right file?

If not, which one should I use?

Thanks!

È stato utile?

Soluzione

In addition to the scripts required by Kendo UI you must include the Angular library scripts and the Angular/Kendo integration script.

Here is a full example:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Angular + Kendo</title>
    <link rel="stylesheet" href="//cdn.kendostatic.com/2014.1.416/styles/kendo.common.min.css">
    <link rel="stylesheet" href="//cdn.kendostatic.com/2014.1.416/styles/kendo.bootstrap.min.css">
    <script src='//code.jquery.com/jquery-1.9.1.js'></script>
    <script src="//cdn.kendostatic.com/2014.1.416/js/kendo.all.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.min.js"></script>
    <script src="//kendo-labs.github.io/angular-kendo/angular-kendo.js"></script>
</head>
<body ng-app="angular-kendo-example">
    <div ng-controller="GridController">    
        <div kendo-grid k-options="options" k-data-source="northwind"></div>
    </div>

    <script>
        angular.module('angular-kendo-example', ['kendo.directives']);

        function GridController($scope) {
            $scope.options = {
                sortable: true,
                pageable: true,
                columns: [{
                    field: "FirstName",
                    title: "First Name",
                    width: "120px"
                },{
                    field: "LastName",
                    title: "Last Name",
                    width: "120px"
                },{
                    field: "Country",
                    width: "120px"
                },{
                    field: "City",
                    width: "120px"
                },{
                    field: "Title"
                }]
            };

            $scope.northwind = {
                type: "odata",
                transport: {
                    read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees"
                },
                pageSize: 5,
                serverPaging: true,
                serverSorting: true
            };
        }
    </script>
</body>
</html>

Here is a link to a running fiddle.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top