MVC KENDO UI GRID - 动态列对象

时间:2014-07-29 10:45:50

标签: asp.net-mvc kendo-ui telerik telerik-grid

您好我正在构建一个具有动态列的网格,具体取决于特定对象的数量..这是一个示例

   public class Team
   {
       string name {get;set;}
       List<members> memberslist {get;set;}
     }

     public class member{
       string name {get;set;}
       int goals {get;set;}
      }

在视图中:

      @(Html.Kendo().Grid(Model.TeamList)
        .Name("goalslist")
        .Columns(columns =>
        {
            columns.Bound(team => team.name).Title("Team Name");
            columns.Bound(team => team.memberslist);

        }...

我想要的结果是这样的:

球队名称,John Smith Taylor Fernandez

阿贾克斯22 1 3
米兰0 1 2

任何Ideia?!它的完成将如何打印对象[对象],我尝试了很多stufs但没有成功..谢谢

1 个答案:

答案 0 :(得分:0)

最简单的方法是通过JSON。将列列表转换为json并将其传递给列,请参见下文。在最底部,您可以看到我将列推到网格中。在下面你可以看到JSON本身的样子。

  var gridJSON = {
        dataSource: {
            data: data,
            schema: {
                model: {} // the model gets filled in by the JSON coming from the database
            },
            pageSize: 20
        },
        height: 550,
        groupable: false,
        sortable: true,
        resizable: true,
        filterable: {
            extra: false,
            operators: {
                string: {
                    startswith: "Starts with",
                    eq: "Is equal to",
                    neq: "Is not equal to"
                }
            }
        },
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
        toolbar: kendo.template($("#template").html())
    };

    gridJSON.columns = currentReport.JSON.columns;
    gridJSON.dataSource.schema.model.fields = currentReport.JSON.fields;

以下是&#39; currentReport.JSON.columns&#39;

的JSON
"columns" : [{
            "field" : "ReceiverID",
            "title" : "Receiver ID"
            }, {
            "field" : "ReceiverBatchID",
            "title" : "Batch ID"
            }, {
            "field" : "PoNumber",
            "title" : "PO Number"
            }, {
            "field" : "ReceiverTransactionDate",
            "title" : "Receiver Trans Date",
            "format" : "{0: yyyy-MM-dd}"
            }, {
            "field" : "PrintingLocation",
            "title" : "Location"
            }, {
            "field" : "VendorID",
            "title" : "Vendor ID"
            }, {
            "field" : "InNemo",
            "title" : "InNemo"
            }, {
            "field" : "Path",
            "title" : "Path",
            "encoded" : "true",
            "template": "#=Path#",
            "width" : "50"
        }
    ]