Login Register

complex values in model sent to grid

hi all,
I want to do something like below with a grid but it seems I can't use complex values in a dojo.data.ItemFileReadStore:

var subrow = [
  name: 'MyCol', field: "myField", formatter: formatField }
];
function formatField(value) {
  return "<b>'+value[0]+"</b><br/>"+value[1];
}

and the data I return from the server is something like

{ 
  identifier: "myId",
  label: "myId",
  items: [
   { myId: "1", 
     myField: ["a","b"]
   }
  ]
}

is such a thing possible? I get the string "undefined" displayed in the cells of the grid.

solution

I figured it out, my solution was as follows:

I changed the data returned by the server to

{ 
  identifier: "myId",
  label: "myId",
  items: [
   { myId: "1", 
     myField: "[\"a\",\"b\"]"
   }
  ]
}

then in my formatter I did

function formatField(value) {
  var v = dojo.fromJson(value);
  return "<b>'+v[0]+"</b><br/>"+v[1];
}