Kendo网格 - 最多分3列

时间:2017-06-26 10:55:42

标签: jquery arrays kendo-ui kendo-grid

我需要将我的Kendo jQuery Grid中的分组限制为最多3列。 我知道我需要使用数据绑定事件来执行此操作,并且需要使用error TS2345: Argument of type '{ [x: string]: string | boolean; }' is not assignable to parameter of type 'Pick<IState, "password" | "email">'. Property 'password' is missing in type '{ [x: string]: string | boolean; } 并从数组中删除新列。也许最好的方法是存储以前的&#39;分组然后比较新旧数组以查看哪个列是新列,然后删除它?

1 个答案:

答案 0 :(得分:2)

您可以取消group事件中的分组,如下所示:

&#13;
&#13;
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Kendo UI Snippet</title>

    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.rtl.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.silver.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.2.621/styles/kendo.mobile.all.min.css"/>

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script>
</head>
<body>
  
<div id="grid"></div>
<script>

  $("#grid").kendoGrid({
    columns: [
      { field: "name" },
      { field: "age" },
      { field: "test" }
    ],
    dataSource: {
      data: [
        { id: 1, name: "Jane Doe", age: 30, test: 1 },
        { id: 2, name: "John Doe", age: 33, test: 2 }
      ],
      schema: {
        model: { id: "id" }
      }
    },
    groupable: true,
    group: function(e) {
      if (e.groups.length > 2) {
        e.preventDefault();
        console.log("Group prevented");
      }
    }
  });
</script>
</body>
</html>
&#13;
&#13;
&#13;