【问题标题】:Kendo Grid - Grouping and logicKendo Grid - 分组和逻辑
【发布时间】:2015-10-27 13:00:13
【问题描述】:

我有一个关于剑道网格和分组的问题 - 我想在分组网格时加入一些逻辑。我需要按州对地址进行分组,如果州为空,则按国家/地区分组。这是可行的吗?谢谢。

【问题讨论】:

    标签: kendo-ui kendo-grid


    【解决方案1】:

    您可以创建一个隐藏列,该列具有可用的状态,否则国家/地区,然后将数据源设置为按该列分组:

    var jsondata = [  
      {City : "Houston",State : "Texas",Country : "USA"}, 
      {City : "New York",State : "New York",Country : "USA"},
      {City : "Austin",State : "Texas",Country : "USA"}, 
      {City : "London",State : "",Country : "UK"}, 
      {City : "Manchester",State :"",Country : "UK"}, 
      {City : "Paris",State : "",Country : "France"}
    ]; 
    
    for (var i=0; i < jsondata.length; i++){
      var stateCountry =  jsondata[i].State ? jsondata[i].State : jsondata[i].Country;
    
      jsondata[i].Group = stateCountry;
    }
    
    $(document).ready(function() {
        $("#grid").kendoGrid({
            dataSource: {
                data: jsondata,
                schema: {
                    model: {
                        fields: {
                            City: { type: "string" },
                            State: { type: "string" },
                            Country: { type: "string" },
                        }
                    }
                },
                group: {
                    field: "Group",
                    dir: "asc"
                }
            },
            groupable: false,
            scrollable: true,
            columns: [
                { field: "City" },
                { field: "State" },
                { field: "Country" },
                { field: "Group", title: "State/Country", hidden: true }
            ]
        });
    });
    

    DEMO

    【讨论】:

    • 感谢您的回复 - 我们有一个 XML 数据源 - 它也可以使用吗?
    • @ElizabethM42,这适用于任何数据源类型。对于 XML,您需要修改创建隐藏列的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 2014-05-28
    相关资源
    最近更新 更多