0

I am using Jqgrid plugin to represent the xml data fetched from DB. I am representing 5 columns out of say 8 columns fetched from DB. Based on one of the column value, I want to represent the row with distinctive colors. for e.g, if i represent employee data like employee no, first name, last name, joined date, status(working or left), i want all the employees currently employed in one color say 'white' and those who left in 'grey'.

Please let me know if this can be done through custom formatter? i am not able get the values through rowObject, options.

Is there a way to style for a row based on column value.

thanks in advance

mayank
  • 21
  • 1

2 Answers2

0

how are you, there is a way but is not with rowOptions, is all jQuery.

 $('#(GridID)').find('tr td[aria-describedby="(GridID)_(ColumnIndex)"]').each(function(ind,val){ 
//Do stuffs, an example:
$(this).text()=="Client 1"?$(this).css('background','Red'):$(this).css('background','Blue')});

if you wanna try open this

http://jsfiddle.net/5USLz/

Good Luck!

0

I hope that this and this answers together will gives you the answer question.

Community
  • 1
  • 1
Oleg
  • 219,533
  • 32
  • 395
  • 775
  • I got the first problem resolved for fetching rowObj in custom formatter, but i still am not able to get solution for 2nd problem, which is to set the background color for the entire row(not just one cell), based on the value of one of the cell – mayank Mar 27 '11 at 12:45
  • @mayank: If you need modify the background color for the **entire row** and not for the cell, the custom formatter is the wrong way. You should do the changes inside of `loadComplete` event handler. The `var myrows = $("#list tbody > tr.jqgrow")` will gives you array of rows. `$("td:nth-child("+(j+1)+")", myrows[i])` will gives you the j-th `` element from the i-th row (the rowid is `myrows[i].id`). In http://stackoverflow.com/questions/5010761/linking-from-a-column-value-in-jqgrid-to-a-new-page-using-get/5017528#5017528 you find `getColumnIndexByName` which help you to calculate j by name – Oleg Mar 28 '11 at 11:50