Reputation: 779
I have a jqGrid field I settled as like:
colModel: [
....,
{name:'Enabled',index:'Enabled',width:45,editable:true,edittype:'checkbox',
editoptions:{value:"1:0"},
formatter: function (cellvalue, options, rowdata) {
if (cellvalue == 0) return "<span class='ui-icon ui-icon-close hidden-align' style='text-align: center'></span>";
else return "<span class='ui-icon ui-icon-check hidden-align' style='text-align: center'></span>";
},align:'center',formatoptions:{disabled:false}},
],
The matter is since I put images in the cellvalue, how I can pass to the Form Editing the value so the checkbox can be in checked state when the cellvalue is true?
Thanks in advance to all! Cheers, Luigi
Upvotes: 2
Views: 922
Reputation: 221997
You can use
formatter: function (cellvalue, options, rowdata) {
if (cellvalue == 0) {
return "<span class=\"ui-icon ui-icon-close\"></span>";
} else {
return "<span class=\"ui-icon ui-icon-check\"></span>";
}
},
edittype: 'checkbox', editoptions: {value:
"<span class=\"ui-icon ui-icon-check\"></span>:<span class=\"ui-icon ui-icon-close\"></span>"}
or better to use no editoptions: { value: ...
, but use formatter
having one from the following values inside: false
, 0
, no
, off
, undefined
. See the lines of jqGrid code
if(tmp.search(/(false|0|no|off|undefined)/i)<0 && tmp!=="") {
$("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked",true);
$("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked",true); //ie
} else {
$("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("checked", false);
$("#"+nm,"#"+fmid)[$t.p.useProp ? 'prop': 'attr']("defaultChecked", false); //ie
}
for the explanation. For example the formatter
formatter: function (cellvalue, options, rowdata) {
if (cellvalue == 0) {
return "<span class=\"ui-icon ui-icon-close\">0</span>";
} else {
return "<span class=\"ui-icon ui-icon-check\">1</span>";
}
}
(without editoptions: { value: ...
) should solve your problem.
Upvotes: 1