简体   繁体   English

Kendo UI网格服务器端分组(无MVC)

[英]Kendo UI Grid Server Side Grouping (without MVC)

Can anyone give an example of JSON data that is returned from a service and consumed by a Kendo Grid (pure JavaScript)? 谁能举例说明从服务返回并由Kendo Grid(纯JavaScript)使用的JSON数据吗? There isn't a lot of information on serverGrouping using their pure Javascript UI controls...so I am wondering if anyone has gotten this to work. 使用纯Javascript UI控件的serverGrouping信息不多...所以我想知道是否有人能使用它。

Your service could return json like this (you could of course include columns, data types, etc.): 您的服务可以这样返回json(您当然可以包括列,数据类型等):

{  
  groupBy: "Discontinued",  
  rows: [
    {ProductName : "Chai",UnitPrice : 18.0000,UnitsInStock : 39,Discontinued : false,}, 
    {ProductName : "Chang",UnitPrice : 19.0000,UnitsInStock : 17,Discontinued : false,},
    {ProductName : "Aniseed Syrup",UnitPrice : 10.0000,UnitsInStock : 13,Discontinued : false,}, 
    {ProductName : "Chef Anton's Cajun Seasoning",UnitPrice : 22.0000,UnitsInStock : 53,Discontinued : false,}, 
    {ProductName : "Chef Anton's Gumbo Mix",UnitPrice : 21.3500,UnitsInStock : 0,Discontinued : true,}, 
    {ProductName : "Grandma's Boysenberry Spread",UnitPrice : 25.0000,UnitsInStock : 120,Discontinued : false,}
  ]
};     

Then your grid definition would use the groupBy in the datasource: 然后,您的网格定义将在数据源中使用groupBy:

$("#grid").kendoGrid({
    dataSource: {
        data: jsondata.rows,
        schema: {
            model: {
                fields: {
                    ProductName: { type: "string" },
                    UnitPrice: { type: "number" },
                    UnitsInStock: { type: "number" },
                    Discontinued: { type: "boolean" }
                }
            }
        },
        group: {
            field: jsondata.groupBy,
            dir: "asc"
        }
    },
    groupable: true,
    scrollable: true,
    columns: [
        "ProductName",
        { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" },
        { field: "UnitsInStock", title: "Units In Stock", width: "130px" },
        { field: "Discontinued", width: "130px" }
    ]
});

DEMO DEMO

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

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