2

I have read some post but I'm still can't follow due to i'm new in jqgrid. I have a jqgrid which have 5 columns, but 1 column is empty for the beginning. After do some update it would be filled.

I want JQgrid change the font color for this row, so if it is filled this row will be change the font color to blue.

jQuery("#list").jqGrid({
....
colModel :[ 
        {name:'prob_id', index:'prob_id', hidden:true, width:10}, 
        {name:'Model',index:'Model',width:100,editable:true,search:true,stype:'text',searchoption:{sopt:['cn']}}, 
        {name:'Serial', index:'Serial',width:80,editable:true,search:true,stype:'text',searchoptions:{sopt:['cn']}},
        {name:'Lotno', index:'Lotno', width:50, editable:true,
                 search:true,
                 stype:'text',
                 searchoption:{sopt:['cn']}},
        {name:'Detail', index:'Detail', hidden:true,width:70,formatter:myformat}
                                        ],
....

function myformat ( cellvalue, options, rowObject )
                {
                        if (!empty(cellvalue)){
                        return '<font color="blue">' + cellvalue + '</font>';//or use classes
                        } else{
                        return '<font color="black">' + cellvalue + '</font>';//or use classes
                        }
                }

I would like to change the font color for all rows that have a value for the Detail Field

but I get an error:

empty is not defined 

UPDATE

try this way : I'm decided to move the condition to :

function myformat ( cellvalue, options, rowObject )
                {
                        if (cellvalue == "closed"){
                        return '<font color="blue">' + cellvalue + '</font>';//or use classes
                        } else{
                        return '<font color="black">' + cellvalue + '</font>';//or use classes
                        }
                }

and it works, but it seems just one column which turn to blue, I want entire row which have condition CLOSED.

nunu
  • 2,703
  • 9
  • 33
  • 55
  • try with this if (!null(cellvalue)) – Kvadiyatar Feb 16 '13 at 09:58
  • @Kvadiyatar: error, show : `object is not a function ` – nunu Feb 16 '13 at 10:00
  • can u try with this one : if(cellvalue != Null) ...plz let me know if still get error. – Kvadiyatar Feb 16 '13 at 10:03
  • not show error but font color not change. – nunu Feb 16 '13 at 10:11
  • it's goes on if condition or else condition? ...you can check it by alert function...one should be in if & one alert should be on else conition...may be it's goes on else...so, as per that condition. you cant get font color. – Kvadiyatar Feb 16 '13 at 10:17
  • Actually whats the need of if condition there ? If there is no value then the value wont be displayed so whats the need of font color for the empty string. – Kris Feb 16 '13 at 10:26
  • If you are trying to give cell background color as per your condition then it has logic – Kris Feb 16 '13 at 10:31
  • If you still want to check, try this if(cellvalue != null && cellvalue !="") – Kris Feb 16 '13 at 10:46
  • I try to put alert in if first then show column's value, then add alert in else (alert show but value nothing). – nunu Feb 18 '13 at 02:08
  • See the answer (will change the entire row color based on condition ), Instead of detail==null || detail=="" check detail=="Closed" in the afterInsertRow – Kris Feb 18 '13 at 04:17

1 Answers1

3

Try afterInsertRow and setRowData like in the code given below

   afterInsertRow: function(rowid, rowData, rowelem) {
   var detail= rowData['Detail'];
   if(detail=="Closed"){
$(this).jqGrid('setRowData', rowid, false, { color: '#000' });
  }else {
$(this).jqGrid('setRowData', rowid, false, { color: '#FF0000' });
    }
    },

Remove gridView:true (afterInsertRow wont work if gridView is true)

Kris
  • 1,882
  • 1
  • 20
  • 23