Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by sp on Apr 24, 2009 16:07
open dhtmlx forum
setting cell attributes for json-loaded grids

I am porting a grid to JSON that was previously loaded via XML like the following

<rows>
<row id="xxx">
<cell image="folder.gif">foo</cell>
<cell>bar</cell>
</row>
</rows>

the problem is the image="" cell attribute. I realize that I cannot directly do it this way, so I'm sending the image filename back as a userdata attribute, and then trying to set the cell attribute in JS directly via:

mygrid.setOnLoadingEnd(loadingEnd);

...

function loadingEnd() {
for (var i=0; i<mygrid.getRowsNum(); i++) {
id = mygrid.getRowId(i);
image = mygrid.getUserData(id, "image");
if (image != null) {
cell = mygrid.cellById(id, 0);
cell.setAttribute("image", image);
}
}
}

I added some debug statements and the cell's "image" attribute is being properly set (according the getAttribute), but I am not seeing the behavior I want (the row has child rows and I want a folder icon to appear instead of the leaf icon). Everything else is working properly (I see the +/- box and the child rows display when the folder is expanded). I just need the icon to be correct.

Do I need to refresh the cell/grid somehow for the changes to take effect? Or is what I'm trying to do not possible?

Answer posted by dhxSupport on Apr 25, 2009 04:13

Actually you can set attributes into the JSON format:

rows:[

{id:1001,

data:[
  {"value":"100","image":"folder.gif"},
  "A Time to Kill",
  "John Grisham",
  "12.99",
  "1",
  "05/01/1998"]}
]

Please check the attachment

Attachments (1)
data.json929.00 B