Search code examples
springjqgrid

jqgrid formatting based on certain value. spring jqgrid


I am new to the JQGRID, I need to format jqgrid based on certain values, lets say if the "NAME" column contains value of "HEMA" and "RAJU" then their respective row should contain the value of n/a (meaning their gender, mobile, location , country should be n/a). I am stuck as I could not figure out how to approach this problem in jqgrid. Guidance will be highly appreciated. I have attached image for clear explanation.

I did some searching but could not find anything closest I could find was formatter but did not work.

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


Solution

  • Guys I was able to fix it using formatter. Spent good amount of time and finally got it fixed.

    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},