简体   繁体   English

使用Angular JS的剑道网格中的工具栏“列菜单”

[英]Tool bar Column Menu in kendo grid using angular js

How to put a column menu in toolbar of a kendo grid to select the columns as per need? 如何在Kendo网格的工具栏中放置列菜单以根据需要选择列?

dataSource: $scope.kDisplayReceivedOrders,
            toolbar: ["save", "cancel",
                {
                    template:
                        '<button class="k-button k-button-icontext " ng-click="confirmReceivedOrder()" >Confirm</button>' +
                        '<button class="k-button "  ng-click="printReceivedOrderDetails()">Print</button>'
                }
            ],

You cannot insert the columnMenu froma a Kendo grid inside a toolbar because Kendo add it to the current grid. 您不能从工具栏内的Kendo网格中插入columnMenu,因为Kendo会将columnMenu添加到当前网格中。

But what you could do is a self implementation of the behavior of this menu inside your own toolbar. 但是,您可以做的是在自己的工具栏中自动实现此菜单的行为。 I have done it recently for a project. 我最近为一个项目完成了它。

What I have done: 我做了什么:

  • An angular component. 角度分量。
  • When clicking on the component I read what columns are visible. 单击该组件时,我会看到可见的列。
    • I do that throgh the .getOptions() and then inspecting the columns property of the object returned. 我通过.getOptions()完成该操作,然后检查返回对象的columns属性。 The invisible columns will have a hidden=true . 不可见的列将具有hidden=true
  • Then in the template I show all the columns with a checkbox to switch the visibility. 然后,在模板中,我显示所有列并带有一个复选框,以切换可见性。
  • hideColumn() and showColumn() should be attached to the action of checking or unchecking a checkbox. hideColumn()showColumn()应该附加到选中或取消选中复选框的操作。

Angular component controller: 角组件控制器:

init() {
 if(this.grid)
  this.columns = getColumns(this.grid.getOptions().columns);
}

checkbox(column) {
  column.visible === true ? this._objectViewService.grid.showColumn(column.field) : this._objectViewService.grid.hideColumn(column.field);
}

A method to convert from kendo defaults to my visualization system: 从kendo默认转换为我的可视化系统的方法:

function getColumns(columns) {
 let cols = [];
 columns.forEach(column => cols.push({title: column.title, field:   column.field, visible: column.hidden !== undefined ? !column.hidden : true}));
 return cols;
}

The template: 模板:

<div class="columnDropdownComponent">
 <p class="title" ng-mouseover="$ctrl.init()">
  <button>Columns<span class="icon-navigation-down"></span></button>
 </p>
 <div class="dropdown">
  <div class="group">
   <label ng-repeat="column in $ctrl.columns" ng-class="{'checked': column.visible}">
    {{column.title}}
   <input type="checkbox" ng-model="column.visible" ng-click="$ctrl.checkbox(column)">
  </label>
 </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM