views:

6025

answers:

5

In "Custom data tooltips in jqGrid 3.4" discussion, came to know how to use setcell to change the color of the text inside a cell of jqgrid. How can we change the background color of the cell?

Tried the following

jQuery("#list").setCell (row,col,'',{ background-color:'red'})

jQuery("#list").setCell (row,col,'','',{ bgcolor:'red'}

Thanks.

A: 

jQuery('#list').setCell('12','name','',{'background-color': 'red'},'');

Are you putting the right row id? The right colName?

You are also missing the quotes in background-color.

Daniel Moura
Agree about css, but I'd use a jqGrid custom formatter to add a class to the td and then build the CSS around classes, not position. Remember, there are plug-ins which allow users to re-order columns!
Craig Stuntz
@Craig Stuntz: I changed my answer to use the method provided by sachin. When the users re-order columns the grid is generated again and it looses all it's classes.
Daniel Moura
+1  A: 

Hi,

$("#list tr:nth-child(3) td:nth-child(2)").css("color", "red"); => Works

$("#list tr:nth-child(3) td:nth-child(2)").css("background-color", "red"); => Doesnt Work.

Did the above work for you with jqgrid? I am using IE. thanks.

sachin
You should edit your question or make a comment on my answer. The above worked for me. I edited my answer using the method you tried. I didn't tried in IE but it should work.
Daniel Moura
Hi,Found the issue. The jquery set cell api works. I was using the redmond.css file and it was overwriting the api changes. thanks for your help.
sachin
A: 

"the redmond.css file and it was overwriting the api changes" I am having the same problem but how to get around this? Can someone elaborate

alias
+1  A: 

Use background instead of specific rules like background-color:

jQuery("#list").setCell (row,col,val,{background:'#ff0000'});
Jon Weers
A: 
jQuery("#list").setCell (row,col,'',{ 'background-color':'red'})

This did not work in IE for me (fine in firefox and chrome), so I did what Jon Weers suggested and switched to:

jQuery("#list").setCell (row,col,'',{'background':'#ff0000'});

and this worked in firefox, chrome, and IE for me.

Sorry, my account is too new to vote up, or apparently comment, otherwise I'd simply vote up Jon's post.

Aaron Baker