how to hide particular column when insert new record in kendo grid -
hey hi try insert new record using kendo grid.
it's work fine.
want set hide , show.
when new hide second column.
on row not other all.
here code:-
<!doctype html> <html> <head> <link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.common.min.css" rel="stylesheet" type="text/css" /> <link href="http://cdn.kendostatic.com/2012.3.1315/styles/kendo.default.min.css" rel="stylesheet" type="text/css" /> <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> <script src="http://cdn.kendostatic.com/2012.3.1315/js/kendo.all.min.js"></script> <script> $(document).ready(function () { var users = [{ userid: 1, username: "robin", isadmin: true } , { userid: 2, username: "hood", isadmin: false }]; var t = $("#grid").kendogrid({ datasource: { data: users, pagesize: 10 }// binding data ,pageable: true , selectable: "multiple row" , toolbar: ["create"] , columns: [ { field: "userid" } , { field: "username"}, { command: "destroy", title: " ", width: "100px" } ], editable: true, edit: function(e) { if(e.model.isnew()) { $("td:nth-child(2)").css("display","none"); } } }); }); </script> <meta charset=utf-8 /> <title>js bin</title> </head> <body> <input type="button" value="iterate" onclick="iterate()"/> <div id="grid"></div> </body> </html>
please if possible when insert new record hide there second td.
thanks.
try this,
below code set in document.ready
$(".k-button,.k-button-icontext,.k-grid-add").click(function(){ var activitygrid = $("#grid").data("kendogrid"); activitygrid.hidecolumn(1); });
updated code:
var cnt = 1; $(".k-button,.k-button-icontext,.k-grid-add").click(function () { cnt = 0; }); var hidefieldname = "username"; $(".k-textbox").live("focusin", function (e) { if (cnt == 0) { if ($(this).attr("name") == hidefieldname) { if ($(this).closest('tr').index() == cnt) { $(this).attr("readonly", "readonly"); } } } });
so, below code worked per requirement. in case textbox generated user can't enter value.
let me know if issue....
Comments
Post a Comment