User Guide

126 CellRenderer API
Because a cell might not exist on the Stage (it might be scrolled out of the display area or it
might be reused to render another value) at any time, you cannot directly reference a specific
cell renderer instance in the grid.
Instead, use the data provider to communicate with a specific cell in the grid. The data
provider holds all the state information about the grid. To display a given cell as enabled or
selected (checked), there should be a corresponding field in the data provider to hold that
information. The
setValue() method of your cell renderer communicates changes in the
data providers state to the cell. The following is a
setValue() implementation from a
theoretical cell renderer that renders a check box in the cells:
function setValue(str, itm, sel)
{
/* Assume the data provider has two relevant fields for this cell : checked
and enabled.
The form of such a data provider might look like this:
[
{field1:"DisplayMe", field2:"SomeString", checked:true, enabled:false}
{field1:"DisplayMe", field2:"SomeString", checked:false, enabled:true}
{field1:"DisplayMe", field2:"SomeString", checked:true, enabled:true}
]
*/
/* Hide anything normally rendered in the cell if itm is undefined.
Otherwise update the cell contents with the new data.
*/
if (itm == undefined){
myCheck._visible = false;
}else{
// redundancy checking
if (myCheck.selected!=itm.checked){
myCheck.selected = itm.checked;
}
if (myCheck.enabled!=itm.enabled){
myCheck.enabled = itm.enabled;
}
}
}