如何有条件地隐藏或显示Kendo网格中的列 [英] How to hide or show the columns in Kendo grid conditionally
问题描述
如果必须在剑道网格中隐藏一列,通常会编写此代码.
We usually write this if we have to hide a column in kendo grid.
{ field: "Name", hidden: true },
但是我想在隐藏状态下使用条件.正确或错误来自另一个字段(即HideShow)中的数据库.如果可以设置的话,有什么选择.
but I want to use condition in the hidden. The true or false would come from database in another field i.e HideShow. Is there any option if I can set this.
{ field: "Name", hidden: HideShow},
HideShow = true/false将从数据库中获取记录时设置.
HideShow = true/false will be set while getting records from database.
我也尝试过通过jquery隐藏和显示,但是显示时会扭曲网格布局.隐藏工作正常.
I have tried hide and showing by jquery also but it is distorting the grid layout while showing. Hide is working fine.
推荐答案
为网格定义DataBound事件,然后决定隐藏列.下面是一个示例:
Define a DataBound event for your grid and there decide to hide the columns. Below is a sample:
<script>
var grid = $("#myGrid").data("kendoGrid");
grid.bind("dataBound", grid_dataBound);
<script>
function grid_dataBound() {
if (MustBeHide)
this.hideColumn("Name");
}
</script>
这将隐藏名称"列.
您还可以按列隐藏列索引,就像这样:
You can also hide the column by column index, Like this:
function grid_dataBound() {
if (MustBeHide)
this.hideColumn(1);
}
这篇关于如何有条件地隐藏或显示Kendo网格中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!