在Telerik Kendo Grid中对服务器进行分组时返回的数据结构是什么?



我有一个使用ajax数据源的teleerik Kendo Grid,它调用asp.net MVC端点。我在服务器端进行排序和分页,这一切都很好。

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

我的问题如何从我的mvc端点返回的数据是结构化的。

例如,我目前返回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 }                                            }
            }
        }

如果我通过"构建"分组,我的数据/模式应该如何结构化?

注释中的附加信息

我的Controller方法是这样的

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

所有的分页、排序、分组数据都被序列化到输入方法中。我使用实体框架从我的数据库中收集数据。

排序通过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()

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

例如,我是否需要像

那样构造返回数据?
{
"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"  
          }
        ]
    }
}

包含空聚合集合非常重要。剑道抛出一个异常。

使用像

这样的数据源模式
 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 }                                            }
        }
    }

最新更新