javascript - How to make cell editable dynamically in jqGrid -


i new jqgrid , need scenario not able figure out.

i able make cell un-editable using following code:

jquery("#updassist").jqgrid('setcell',rowid,'precpsprog','','not-editable-cell'); 

now want make cell editable again based on condition.

what class should use achieve that?

is there 'editable-cell' class can use?

you should remove 'not-editable-cell' class cell (<td> element)

td.removeclass('not-editable-cell'); 

you should select cells (<td> element) want make editable.

i made the demo demonstrate how this. important code fragment demo is

var grid = $("#list"); var getcolumnindexbyname = function(gr,columnname) {     var cm = gr.jqgrid('getgridparam','colmodel');     (var i=0,l=cm.length; i<l; i++) {         if (cm[i].name===columnname) {             return i; // return index         }     }     return -1; }; var changeeditablebycontain = function(gr,colname,text,dononeditable) {     var pos=getcolumnindexbyname(gr,colname);     // nth-child need 1-based index use (i+1) below     var cells = $("tbody > tr.jqgrow > td:nth-child("+(pos+1)+")",gr[0]);     (var i=0; i<cells.length; i++) {         var cell = $(cells[i]);         //var celltext = cell.text();         var unformatedtext = $.unformat(cell,{rowid:cell[0].id,                                         colmodel:gr[0].p.colmodel[pos]},pos);         if (text === unformatedtext) { // 1 can use cell.text() instead of                                        // unformatedtext if needed             if (dononeditable) {                 cell.addclass('not-editable-cell');             } else {                 cell.removeclass('not-editable-cell');             }         }     } }; grid.jqgrid({     datatype: "local",     ...     celledit: true,     cellsubmit: 'clientarray',     loadcomplete: function() {         changeeditablebycontain(grid,'name','test',true);     } }); $("#doeditable").click(function(){     changeeditablebycontain(grid,'name','test',false); }); $("#dononeditable").click(function(){     changeeditablebycontain(grid,'name','test',true); }); 

in demo cells 'client' column having text "test" marked "non-editable". later 1 can make cells "editable" or "non-editable" clicking on corresponding button.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -