How to hide or show the columns in Kendo grid conditionally

不羁岁月 提交于 2020-04-30 05:01:17

问题


We usually write this if we have to hide a column in kendo grid.

 { field: "Name", hidden: true },

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 will be set while getting records from database.

I have tried hide and showing by jquery also but it is distorting the grid layout while showing. Hide is working fine.


回答1:


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>

This will hide "Name" column.

You can also hide the column by column index, Like this:

function grid_dataBound() {
   if (MustBeHide)
      this.hideColumn(1);
}



回答2:


You can perform it on Edit: onGridEditing. Following is function:

 function onGridEditing(arg) {
        if (true) {
            $('label[for=Name]').hide();
            $('div[data-for=DesignationID]').hide();
        }
        else {
            $('label[for=Name]').show();
            $('div[data-for=DesignationID]').hide();
        }
 }

Hope this will help you.



来源:https://stackoverflow.com/questions/38137305/how-to-hide-or-show-the-columns-in-kendo-grid-conditionally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!