Kendo Grid columns Hide Show, Enable/Disable

I am going to share the code sample for show/hide, enable/disable columns using kendo ui grid as given below.

Table of Contents

1. Kendo ui code sample using MVC 4
2. jQuery code sample

Kendo ui code sample using MVC 4

model IEnumerable<PCX.Models.Contract>
    PCX.Models.UserSession userSession = (PCX.Models.UserSession)Session["userSession"];

            .Resizable(e => e.Columns(true))
            .Columns(columns =>
                columns.Bound(clm => clm.CompanyName).Title("Company Name")
                        .Filterable(flt => flt.UI("CompanyFilter"));
                columns.Bound(clm => clm.name).Title("Contract Name");
                columns.Bound(clm => clm.installationdate).Title("IDate")
                       .Format("{0:dd MMM yyyy}").Filterable(false);
                columns.Bound(clm => clm.startdate).Title("SDate");
                columns.Bound(clm => clm.enddate).Title("EndDate").Filterable(false);
                columns.Template(clm => @Ajax.ActionLink("Renewal"
                                 "Create", "ServiceContract"
                                   new { ID = clm.ContractID }, 
                                   new AjaxOptions { HttpMethod = "Post" }, 
                                   new { @class = "btn btn-primary" })).Width(100);
         .Filterable(filterable => filterable

jQuery Code Sample

<script type="text/javascript">
    $(document).ready(function () {
        var role = '@User.IsInRole(userSession.TenantID + "_Admin")';
        if (role) {
            var grdView = $('#ContractExpiration').data('kendoGrid');
            grdView.hideColumn("CompanyName"); //By Using Columns Name.
            grdView.hideColumn(3);//By Using Index of columns.



Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions