简体   繁体   English

使Kendo Grid工作

[英]getting Kendo Grid working

I've simplified this to its barebones - pulled out any properties that might be interfering (I can put em back in if you like) - even pointing it at local .json - and still getting no data in my grid. 我已将其简化为准系统-删除了可能会干扰的所有属性(如果您愿意,我可以将它们放回去)-甚至将其指向本地.json-并且在网格中仍然没有数据。

I did see data in the sample that I dropped in, when it was pointing at the Northwind api, so I know I've got my i's crossed and t's dotted. 当它指向Northwind api时,我确实看到了样本中的数据,所以我知道我已经划线了,点划线了。

        <div id="grid"></div>

This is in my controller: 这是在我的控制器中:

        $("#grid").kendoGrid({
            dataSource: {
                type: "odata",
                transport: {
                    read: 'Content/data/Listings.json'
                }
             },
            height: 550,
           columns: [{
                field: "Id",
                title: "Id",
                width: 240  
            },{
                field: "State",
                title: "State",
                width: 240  
            }]
        });

The call it makes is this (I have no control over this): 它发出的呼叫是这样(我对此无能为力):

http://localhost/Wizmo-web/Content/data/Listings.json?$callback=jQuery112103831734413679999_1470962161424&"%"24inlinecount=allpages&"%"24format=json

It is returning data from my Listings.json (which I've ensured is valid): 从我的Listings.json返回数据(我已经保证了是有效的):

[
   {
      "Id":557,
      "State":"active",
      "Title":"Matching Father Son Shirts I Am Your Father Shirt ",
   },
   {
      "Id":558,
      "State":"active",
      "Title":"Baseball Hoodies Im All About That Base Hooded Swe",
   }
]

But my grid is empty. 但是我的网格是空的。 No errors, no nothing. 没有错误,什么都没有。

Stumped. 难过

I looks like in your controller, you are trying to use the jQuery implementation of Kendo, instead of the supported Angular directives. 我看起来像在您的控制器中,您正在尝试使用Kendo的jQuery实现,而不是受支持的Angular指令。

The Kendo UI grid features inherent integration with AngularJS using directives which are officially supported as part of the product. Kendo UI网格具有使用伪指令与AngularJS进行固有集成的功能,这些伪指令已作为产品的一部分正式支持。 To make use of this integration, you need to reference the Angular scripts in your app and register the module incorporating the Kendo UI directives in the following way: 要利用此集成,您需要在应用程序中引用Angular脚本,并以以下方式注册包含Kendo UI指令的模块:

angular.module("myApp", [ "kendo.directives" ])

So in your controller, instead of using jQuery $("#grid").kendoGrid(...) to find the element and add your config object, you are actually going to use a config object on your controller scope: 因此,在您的控制器中,您实际上将在控制器作用域上使用一个配置对象,而不是使用jQuery $("#grid").kendoGrid(...)查找元素并添加配置对象。

$scope.mainGridOptions = {
    //all your config options here
};

Then in your view, instead of using just <div id="grid"></div> you're actually going to use the Kendo directive here, and pass it the config object from your controller: 然后,在您的视图中,您实际上将在这里使用Kendo指令,而不是仅使用<div id="grid"></div> ,并将其从控制器传递给config对象:

<kendo-grid options="mainGridOptions">
...

Kendo has some pretty good documentation on Angular implementation here Kendo在这里有一些关于Angular实现的很好的文档

The actual problem is different - the dataSource configuration includes a type: "odata" setting, which does not correspond to the server response, so it should be removed. 实际问题有所不同-dataSource配置包括type: "odata"设置,该设置与服务器响应不对应,因此应将其删除。 With this setting, the Kendo UI DataSource instance is not able to find the data items in the returned JSON, that's why no table rows are rendered. 使用此设置,Kendo UI DataSource实例无法在返回的JSON中找到数据项,这就是为什么不呈现任何表行的原因。

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-type http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-type

Here is a runnable example without the type setting: 这是一个没有type设置的可运行示例:

http://dojo.telerik.com/ESija http://dojo.telerik.com/ESija

The moment I add [ 'kendo.directives' ] to the module, everything dies. 当我向模块添加['kendo.directives']时,所有内容都会消失。 No errors, nothing. 没有错误,没事。

Controller: 控制器:

(function() {
    'use strict';

    angular
        .module('WizmoApp', [ 'kendo.directives' ])
        .controller('listingsController', listingsController);

    listingsController.$inject = ['$http', '$location', '$stateParams', '$filter', 'toastr', 'DTOptionsBuilder', 'DTColumnDefBuilder', 'listingsService', 'datatableService', 'ngAuthSettings'];

    function listingsController($http, $location, $stateParams, $filter, toastr, DTOptionsBuilder, DTColumnDefBuilder, listingsService, datatableService, ngAuthSettings) {

...

index.html: index.html:

<script src="Content/vendor/Metronic/global/plugins/jquery.min.js" type="text/javascript"></script>
...
<script src="Content/vendor/Metronic/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="Content/vendor/datatables/media/js/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="Content/vendor/angular/angular.min.js" type="text/javascript"></script>
<script src="Content/vendor/KendoUI/js/kendo.all.min.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM