[英]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: 我做了什么:
.getOptions()
and then inspecting the columns
property of the object returned. .getOptions()
完成该操作,然后检查返回对象的columns
属性。 The invisible columns will have a hidden=true
. hidden=true
。 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.