View Full Version : JSON Rederer

22 Jan 2007, 9:08 PM
Here's a simplified version of my situation.

I have a an object that looks like:

var o = {
Campaigns: [
{Name: 'Some Name 1', Gross: 100, Costs: 50},
{Name: 'Some Name 2', Gross: 300, Costs: 87}

Now in the grid I want to show "Name" and "Profit". How can I get access to the object inside my renderer function?
I was doing something like:

var rend = function(val, row){
var campaign = o.Campaigns[row];
return campaign.Gross - campaign.Costs;

That works great at first, but it breaks when I sort because the rows don't match the object being displayed? Is there another parameter or something for which I can get access to the object that is being rendered?

23 Jan 2007, 8:16 AM
Rather than do it in a renderer, you might do it in a datamodel preprocessor method, which actually populates a new col value. It's been a while, but this is how I have added a rowIndex to the grid on the fly. You might have to experiment with it a little to get other cell values to do the calc. The edit grid examples shows how to add preprocessors.