1、formatter与unformat官网:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter
formatter:functionFormatter(cellvalue, options, rowObject){}
//cellvalue - 当前cell的值
//options - 该cell的options设置,包括{rowId, colModel(当前行的属性),grid(当前表格),pos
//rowObject - 当前row数据,
关于formatter属性应用,推荐博客地址:
http://mj4d.iteye.com/blog/1634857
{name:"paramValue",index:"paramValue",edtiable:false,editType:"text",
formatter:functionimageFormatter(cellvalue, options,rowObject){
if(cellvalue==1){
return “<imgsrc=‘"+contextPath+"/page/img/alarmflag.png'/>”;//图片地址
}elseif(cellvalue==2){
return “<imgsrc=‘"+contextPath+"/page/img/normalflag.png'/>”;//图片地址
}
}
},
动态添加图片到单元格也是修改edittype属性:
$("#editGrid").setColProp("paramValue",{
editytype:"image" ,
formatter:functionimageFormatter(cellvalue, options, rowObject){
if(cellvalue==1){
return “<imgsrc=‘"+contextPath+"/page/img/alarmflag.png'/>”;//图片地址
}elseif(cellvalue==2){
return “<imgsrc=‘"+contextPath+"/page/img/normalflag.png'/>”;//图片地址
}
}
})
$("#editGrid").setColProp("paramValue",{
editytype:"checkbox" ,
editoptions:{value:"ON:OFF"}//value值可以根据需求修改
formatter:functioncheckboxFormatter(cellvalue, options, rowObject){
if(cellvalue==1){
returnON;//当单元格的值为1时,显示在界面的值是ON,即选择
}elseif(cellvalue==2){
returnOFF;//
当单元格的值为2时,显示在界面的值是OFF,即未选择
}
}
unformat:functioncheckboxunformat(
cellvalue, options, rowObject
){
if(cellvalue=="ON"){
return1;//当单元格的值为ON时,即选择,用getRowData获得当前行的 //paramValue的值为1,
}elseif(cellvalue=="OFF"){
return0;
//当单元格的值为OFF时,即未选择,用getRowData获得当前行的 //paramValue的值为0
}
}
}
})
2、formatter处理图片,即让图片显示在单元格中(一般用于不可编辑的行)
3、formatter和unformat处理checkbox(select)