Skip to main content

How to disable specific grid column in kendo ui Grid on inline editing

If you want to stop editing on specific Grid column in Kendo Ui grid like this


Just use theDataAnnotations [Editable(false)] in your custom class for the grid

i am just share my code for your help

 using System;  
 using System . Collections . Generic;  
 using System . ComponentModel . DataAnnotations;  
 using System . Linq;  
 using System . Web;  
 namespace FEWO . ViewModel  
 {  
   public class Limitation  
   {  
     public long Id { get; set; }  
     public int? LFDNR { get; set; }  
     public Guid? ob_guid { get; set; }  
     public DateTime? von { get; set; }  
     public DateTime? bis { get; set; }  
     public string einschrank { get; set; }  
     public string wtagvon { get; set; }  
     public string wtagbis { get; set; }  
     public int numtagvon { get; set; }  
     public int? numtagbis { get; set; }  
     public int? nummonvon { get; set; }  
     public int? nummonbis { get; set; }  
     public int? numjahrvon { get; set; }  
     public int? numjahrbis { get; set; }  
     [Editable(false)]  
     public string ob_name { get; set; }  
      [Editable ( false )]  
     public string ob_code { get; set; }  
     public DateTime FromTag { get; set; }  
     public DateTime ToTag { get; set; }  
     public string FromDay { get; set; }  
     public string ToDay { get; set; }  
   }  
 }  

in your controller for read



  public ActionResult FilterMenuCustomization_Read ( [DataSourceRequest] DataSourceRequest request )  
     {  
       return Json ( GetAllLocation ( ) . ToDataSourceResult ( request ) );  
     }  
     private static IEnumerable<Limitation> GetAllLocation ( )  
     {  
       FEWOEntities db = new FEWOEntities ( );  
       var t_institution = from p in db . einschrank  
        select p;  
       List<Limitation> limitationListObj = new List<Limitation> ( );  
       foreach ( var p in t_institution )  
       {  
         Limitation student = new Limitation ( );  
         student . Id = p . Id;  
         student . ob_guid = p . ob_guid;  
         student . ob_name = p .objects. ob_name;  
         student . ob_code = p .objects. ob_code;  
         student . von = p . von;  
         student . bis = p . bis;  
         student . FromDay =p.FromDay;  
         student . ToDay = p.ToDay;  
         student . einschrank = p . einschrank1;  
         limitationListObj . Add ( student );  
       }  
       // return View ( viewDataInstitutions . ToList ( ) );  
       return limitationListObj;  
     }  


In your index view:

 @model IEnumerable<FEWO.ViewModel.Limitation>  
 @{  
   ViewBag.Title = "Bearbeiten des Mieterstatus";  
 }  
 <h3> einschrankungen</h3>  
 <p>  
   @Html.ActionLink("zusatzleitungen neu", "Create")  
 </p>  
 <script type="text/javascript">  
   function error_handler(e) {  
     if (e.errors) {  
       var message = "Errors:\n";  
       $.each(e.errors, function (key, value) {  
         if ('errors' in value) {  
           $.each(value.errors, function () {  
             message += this + "\n";  
           });  
         }  
       });  
       alert(message);  
     }  
   }  
   function nameFilter(element) {  
     element.kendoAutoComplete({  
       dataSource: {  
         transport: {  
           read: "@Url.Action("FilterMenuCustomization_Names")"  
         }  
       },  
       optionLabel: "--Select Value--"  
     });  
 }  
 function bookingNumber(element) {  
   element.kendoAutoComplete({  
     dataSource: {  
       transport: {  
         read: "@Url.Action("FilterMenuCustomization_BookingNumber")"  
       }  
     }  
   });  
 }  
 function region(element) {  
   element.kendoAutoComplete({  
     dataSource: {  
       transport: {  
         read: "@Url.Action("FilterMenuCustomization_Region")"  
       }  
     }  
   });  
 }  
   function FromDayFilter(element) {  
     element.kendoAutoComplete({  
       dataSource: {  
         transport: {  
           read: "@Url.Action("FilterMenuCustomization_FromDayFilter")"  
       }  
     }  
   });  
 }  
 </script>  
 @(Html.Kendo().Grid(Model)    
   .Name("Grid")  
   .Columns(columns => {  
     columns . Bound ( e => e . Id ) . Hidden ( );  
     columns . Bound ( e => e . ob_guid ) . Hidden ( );  
     columns . Bound ( e => e . ob_name ).Title("Objekt")  
           . Filterable ( filterable => filterable . UI ( "nameFilter" ) )  
         . Width ( 200 );  
     columns . Bound ( e => e . ob_code ) . Title ( "Code" );  
     columns . Bound ( e => e . von ).Title("Von");  
     columns . Bound ( e => e . FromDay ) . Title ( "Von Tag" ) . Filterable ( filterable => filterable . UI ( "FromDayFilter" ) )  
         . Width ( 200 );  
     columns . Bound ( e => e . bis ).Title("Bis");  
     columns . Bound ( e => e . ToDay ).Title("Bis tag");  
     columns . Bound ( e => e . einschrank ).Title("Einschrankung");  
         columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);    
   })  
    .Filterable(filterable => filterable  
     .Extra(false)  
     .Operators(operators => operators  
       .ForString(str => str.Clear()  
         .StartsWith("Starts with")  
         .IsEqualTo("Is equal to")  
         .IsNotEqualTo("Is not equal to")  
       ))  
     )    
   .Editable(editable => editable.Mode(GridEditMode.InLine))  
   .Pageable()  
   .Sortable()  
   .Scrollable()  
    .ColumnMenu()  
    .Selectable()  
     .Groupable()  
      .DataSource(dataSource => dataSource      
     .Ajax().PageSize(20)  
     .Events(events => events.Error("error_handler"))  
     .Model(model => model.Id(p => p.Id))  
     .Read(read => read.Action("FilterMenuCustomization_Read", "Limitations"))  
     .Update(update => update.Action("EditingInline_Update", "Limitations"))  
     .Destroy(update => update.Action("EditingInline_Destroy", "Limitations"))  
    )   
     )   

Comments

Popular posts from this blog

C# run powershell script as administrator

Recently I was fetching a problem that I need to run a PowerShell script that will change TFS user Display name and SID. I was trying to run that script from C# that was not working due to TFS security update and TLS certificate. Using this code block I resolve the Issue. var newProcessInfo = new System.Diagnostics.ProcessStartInfo(); newProcessInfo.FileName = @"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"; newProcessInfo.Verb = "runas"; // Define Run as administrator newProcessInfo.Arguments = script; //Define your powershell script newProcessInfo.UseShellExecute = false; newProcessInfo.RedirectStandardOutput = true; // This will enable to read Powershell run output newProcessInfo.RedirectStandardError = true; Process proces = System.Diagnostics.Process.Start(newProcessInfo); proces.WaitForExit(); // I want to read the output string from powershell window StringBuilder output = new StringBuilder(); output.Append("Started"); while (!proces.St

ASP.NET MVC razor SAP Crystal report

Crete a new project: Add a aspx Master Page Create a new folder Reports and 2 sub folder crystal & crystalviewer Now add a web form page in crystalviewer  folder. Add the master page namespace in your web form page. MasterPageFile ="~/Views/Shared/ReportSite.Master" Replace your web form by this code < asp : Content ID ="Content1" ContentPlaceHolderID ="ContentPlaceHolder1" runat ="server">      </ asp : Content > Now go to design mode of your web form drag & drop the crystal report viewer in your web form. After that your page will be look look like this. Replace the code: < CR : CrystalReportViewer ID ="EmployeeList" runat ="server"   HasCrystalLogo ="False"     AutoDataBind ="True"   Height ="50px"   EnableParameterPrompt ="false" EnableDatabaseLogonPrompt

mvc razor textboxfor change event change another textboxfor value

Based on value of Weight, Rate , CNF & AWB it will change the value of Freight , TTLCNF anfd TTLFright . Freight= Weight*Rate; TTLCNF  = Weight*CNF; TTLFright=  Freight+ TTLCNF  + AWB; @Html.TextBoxFor(model => model.Weight, new { onChange="return GetWight(this);"}) @Html.TextBoxFor(model => model.Rate, new { onChange="return GetWight(this);"})/Kg @Html.TextBoxFor(model => model.Freight, new {disabled = "disabled" , @readonly = "readonly" ,onChange="return GetTTLFright(this);"}) @Html.TextBoxFor(model => model.CNFPK, new { onChange="return GetCNFPK(this);"}) @Html.TextBoxFor(model => model.TTLCNF, new {disabled = "disabled" , @readonly = "readonly",onChange="return GetTTLFright(this);" }) @Html.TextBoxFor(model => model.AWB, new { onChange="return GetTTLFright(this);"}) and script <script> function GetW