基于特定值的jqgrid格式化。春天jqgrid

时间:2019-07-05 11:35:21

标签: spring jqgrid

我是JQGRID的新手,我需要根据某些值设置jqgrid的格式,可以说,如果“ NAME”列包含“ HEMA”和“ RAJU”值,那么它们各自的行应包含n / a值(表示他们的性别,流动性,地理位置,国家/地区应为n / a)。我陷入困境,因为我不知道如何在jqgrid中解决此问题。指导将受到高度赞赏。我已附上图片以进行清楚的说明。

我进行了一些搜索,但是找不到最能格式化的但无法正常工作的东西。

var url = "test/gridresult";
$(function(){
("#result").jqGrid({
   	url:url,
	datatype: "jsonstring",
        multiselect:false,
   	colNames:['Id','NAME', 'GENDER', 'MOBILE','LOCATION','COUNTRY'],
   	colModel:[
   		{name:'id',index:'id', resizable:true},
   		{name:'name',index:'name', resizable:true},
   		{name:'mobile',index:'mobile', resizable:true},
   		{name:'country',index:'country', resizable:true},
   				
   	],
   	rowNum:100,
   	pager: '#prowed1',
sortname: 'id',
    loadonce: true,
    sortorder: "desc",
	jsonReader;{

            repeatitem:false,
            root:"rows",
            page:"page",
            records:"records",
            cell:""
}
});
});


this seems working, I am getting name from loop but how do I set n/a in a row for that particular name
    var rows = $("#result").jqGrid('getDataIDs'); 
    			    for (var i = 0; i < rows.length; i++)
    			    {
    			        var status = $("#resultTable2").getCell(rows[i],"NAME");
    			        alert("initial value "+status);
    			        if(status == "HEMA")
    			        {
    			        	
    			            //need to set value of n/a for row that belongs to HEMA   
    			        }
    			    }


<!-- begin snippet: js hide: false console: true babel: false -->

   

demo pic for my question

1 个答案:

答案 0 :(得分:0)

我可以使用格式化程序修复它。花了很多时间,终于解决了。

function valFormat( cellvalue, options, rowObject ){
	var  val;
if(rowObject.name=='HEMA' ){
val='N/A';
}else{
val=cellvalue;
}
return val;
}


and in the jqgrid:
{name:'name',index:'name', resizable:true, formatter:valFormat},