views:

351

answers:

1

Hi, I am using a jqgrid with a column named 'Comments'. My controller code returns data as follows:


var jsonData = new
{
rows=
....
....
   select new
             {
             col1....
             col2....
             Comments = _Model.GetComments(id),
             })

.......
.....
   return Json(jsonData, JsonRequestBehavior.AllowGet);
}


_Model.GetComments(id) will return a ClientComments Object which has a few properties say CommentID, FirstName, MiddleName etc., which will be bound to each row in the grid

Now in my jqgrid I need to build a tool tip based on Comments column properties and for that I need to use the properties of my Comments in JQGrid for each row. May I know How I can manipulate Comment's properties for each row? Any help would be appreciated.

I tried in my javascript that for each row rowObject.Comments.FirstName and it did not work.

+2  A: 

For the JavaScript version of the grid you would use getDataIDs to get the ID of each row, and then use getRowData to read the data at that row. For example:

var ids = $("#grid").getDataIDs();
for(var i=0; i<ids.length;i++){
   var rowdata = $("#grid").getRowData(ids[i]);

   // Build tooltip here using rowdata.FirstName, rowdata.MiddleName, etc.
}

But, are you working with the JavaScript version of jqGrid or jqGrid ASP.NET component?

Justin Ethier
Hi Justin,THanks for ur help again. I missed a very basic point that some comments might be null. So in my javascript i should first check if(rowObject.Comments != null. Only then I can access rowObject.Comments.whateverproperties in that object. So it works fine now.
SARAVAN
No problem, glad you got it to work!
Justin Ethier