在 Telerik Kendo 网格中的服务器上分组时返回的数据结构是什么

What is the structure of the data returned when grouping on the server in a Telerik Kendo Grid

我有一个使用 ajax 数据源的 telerik Kendo 网格,它调用 aspnet MVC 端点。我在服务器端同时进行排序和分页,一切都很好。

我现在想实现服务器端分组。

我的问题 return 从我的 mvc 端点编辑的数据应该如何构建。

例如我目前 return json 数据喜欢

{
"total": 2,
"data": [
    {
        "RealAssetId": 2,
        "Building": "Building2",
        "Level": "Level2",
        "Zone": "Zone2",
        "Room": "Room2",
        "AssetId": "Asset Id2",
        "AssetCategory": "Asset Gategory2",
        "AssetFamily": "Asset Family2",
        "AssetType": "Asset Type2"
    },
    {
        "RealAssetId": 3,
        "Building": "Building2",
        "Level": "Level3",
        "Zone": "Zone3",
        "Room": "Room3",
        "AssetId": "Asset  Id3",
        "AssetCategory": "Asset Gategory3",
        "AssetFamily": "Asset Family3",
        "AssetType": "Asset Type3"
    }
]

}

我的数据源上有一个架构,例如

 schema: {
            data: "data",
            total: "total",                
            model: {
                fields: {
                    Building: { editable: false },
                    Level: { editable: false },
                    Zone: { editable: false },
                    Room: { editable: false },
                    AssetId: { editable: false },
                    AssetCategory: { editable: false },
                    AssetFamily: { editable: false },
                    AssetType: { editable: false }                                            }
            }
        }

如果我按 "building" 分组,我的 data/schema 应该如何构建。

来自评论的附加信息。

我的控制器方法如下所示

public ActionResult GetDataTasks(int skip, int take, int page, int pageSize, List<SortDto> sort = null, List<GroupDTO> group = null, FilterSetDTO filter = null)

所有的分页、排序、分组数据都很好地序列化到输入法中。我使用 entity framework.

从我的数据库中收集数据

排序是通过 linq 完成的

 if (sort != null && sort.Count > 0)
            {
                foreach (var s in sort)
                {
                    dataTasks = dataTasks.OrderBy(s.field + " " + s.dir);
                }
            }

以及分页,

dataTasks.Skip(skip).Take(take)).ToList()

我还不完全确定我将如何实现分组,但首先我需要弄清楚 return 数据应该是什么形状。

例如,我是否需要将 return 数据结构化为

{
"total": 2,
"data": [
    {
        "Building": "Building2",
        "Data": [
            {
                "RealAssetId": 2,
                "Level": "Level2",
                "Zone": "Zone2",
                "Room": "Room2",
                "AssetId": "Asset Id2",
                "AssetCategory": "Asset Gategory2",
                "AssetFamily": "Asset Family2",
                "AssetType": "Asset Type2"
            },
            {
                "Level": "Level3",
                "Zone": "Zone3",
                "Room": "Room3",
                "AssetId": "Asset  Id3",
                "AssetCategory": "Asset Gategory3",
                "AssetFamily": "Asset Family3",
                "AssetType": "Asset Type3"
            }
        ]
    }
]

}

希望这对您有所帮助。

我在这里找到了更多信息

http://docs.telerik.com/KENDO-UI/api/javascript/data/datasource#configuration-schema.groups

http://www.telerik.com/forums/datasource-remote-grouping

数据的结构需要像

{
"total": 2,
"groups": {
    "field": "Building",
    "value": "Smith Tower",
    "aggregates": [],
    "items": [
        {
            "RealAssetId": 1,
            "Building": "Smith Tower",
            "Level": "Level",
            "Zone": "Zone",
            "Room": "Room",
            "AssetId": "Asset Id",
            "AssetCategory": "Asset Gategory",
            "AssetFamily": "Asset Family",
            "AssetType": "Asset Type"
        },
        {
            "RealAssetId": 2,
            "Building": "Smith Tower",
            "Level": "Level3",
            "Zone": "Zone3",
            "Room": "Room3",
            "AssetId": "Asset  Id3",
            "AssetCategory": "Asset Gategory3",
            "AssetFamily": "Asset Family3",
            "AssetType": "Asset Type3"  
          }
        ]
    }
}

包含空聚合集合很重要。 Kendo 以其他方式抛出异常。

使用类似

的数据源模式
 schema: {
        groups: "groups",
        total: "total",                
        model: {
            fields: {
                Building: { editable: false },
                Level: { editable: false },
                Zone: { editable: false },
                Room: { editable: false },
                AssetId: { editable: false },
                AssetCategory: { editable: false },
                AssetFamily: { editable: false },
                AssetType: { editable: false }                                            }
        }
    }