0

My Application requires an action to be done on a jqgrid.The jqgrid is populated by an html page ,i would like to leave it unchanged .My code gives 2 options

a. color a row depending on the value of a cell
b. insert image in a cell depending on the value of a cell

I would like to do this by accessing the object of jqgrid.For example for hiding columns I did the following

myObject.jqGrid("hideCol",hiddenColumns);
Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
codingBliss
  • 135
  • 5
  • 18
  • Possible duplication of SO,http://stackoverflow.com/questions/4942761/how-to-change-the-color-of-jqgrid-cell & http://stackoverflow.com/questions/16934318/adding-image-in-the-column-of-jqgrid – dreamweiver Dec 31 '13 at 05:19
  • I want to do these operations outside the jqgrid definition,in order to do it dynamically . – codingBliss Jan 02 '14 at 04:20

1 Answers1

0

a. color a row depending on the value of a cell:

//get total rows in you grid
var numberOfRecords = myObjectofGrid.getGridParam("records");
for(var i=1;i<=numberOfRecords;i++)
{
var rowdata =myObjectofGrid.getRowData(i);
var seVal = rowdata.mycolumn;
        switch(seVal){
        case 'red':         myObjectofGrid.jqGrid('setRowData',i,false,'myRedColor-Class');break;
        case 'green' :  myObjectofGrid.jqGrid('setRowData',i,false,'mygreenColor-class');break; 

        }

}

b. insert image in a cell depending on the value of a cell:

myObjectofGrid.setColProp('mycolumn',{formatter:myFormatter}).trigger('reloadGrid');

myFormatter:

function myFormatter (cellvalue, options, rowObject)
{  
      switch(cellvalue){
        case 'img1':        newCell="<img src='../../Content/images/ui-flag_someimg1.png' />"+cellvalue;break;
        case 'img2' :  newCell="<img src='../../Content/images/ui-flag_someimg2.png' />"+cellvalue;break; 
        }                 
    return newCell;
}  
codingBliss
  • 135
  • 5
  • 18