Posts Tagged ‘Code samples’

Code sample: CheckBox as itemRenderer for DataGridColumn (Adobe Flex)

3 Comments »

Another use­ful code sam­ple (orig­i­nally posted on Experts-Exchange.com by yours truly) that allows CheckBox’s to be part of a Data­Grid. This is accom­plished is by set­ting the item­Ren­derer of a Data­Grid­Col­umn to be a Check­Box and han­dling the selected and click prop­er­ties of the CheckBox.

Note: It is impor­tant to set the DataGridColumn’s editable prop­erty to false as the item­Ren­derer itself is the itemEditor.

DataGrid CheckBox

Code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="center" verticalAlign="middle">
<mx:DataGrid id="dataGrid" editable="true">
<mx:dataProvider>
<mx:XMLList xmlns="">
<node isTrue="true" name="xxxxxxxx" location="yyyyyyy"/>
<node isTrue="false" name="xxxxxxxx" location="yyyyyyy"/>
<node isTrue="true" name="xxxxxxxx" location="yyyyyyy"/>
<node isTrue="false" name="xxxxxxxx" location="yyyyyyy"/>
<node isTrue="true" name="xxxxxxxx" location="yyyyyyy"/>
</mx:XMLList>
</mx:dataProvider>
<mx:columns>
<mx:DataGridColumn dataField="@isTrue" width="25" headerText=" " editable="false">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox selected="{(data.@isTrue == 'true')?true:false}" click="{data.@isTrue = (data.@isTrue != 'true') ? 'true' : 'false';}"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="@name" headerText="Name"/>
<mx:DataGridColumn dataField="@location" headerText="Location"/>
</mx:columns>
</mx:DataGrid>
<mx:DataGrid dataProvider="{dataGrid.dataProvider}"/>
</mx:Application>

Code sample: Static data tips for Data Grid Column (Adobe Flex)

No Comments »

Here’s a code sam­ple I pro­vided for a ques­tion posted on Experts Exchange. The asker wanted a sta­tic text tooltip for a par­tic­u­lar col­umn in a data grid. The code below uses the dataTip­Func­tion to pro­vide for the same.

Screen­shot
 data grid column data tip

Code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
public function customDataTip(item:Object):String {
return "custom static data tip";
}
]]>
</mx:Script>
<mx:DataGrid>
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="@name"/>
<mx:DataGridColumn headerText="Age" dataField="@age"/>
<mx:DataGridColumn headerText="Location" dataField="@location" dataTipFunction="customDataTip" showDataTips="true"/>
</mx:columns>
<mx:dataProvider>
<mx:XMLList xmlns="">
<node name="AAA" age="1" location="New Delhi"/>
<node name="BBB" age="2" location="New Delhi"/>
<node name="CCC" age="3" location="New Delhi"/>
</mx:XMLList>
</mx:dataProvider>
</mx:DataGrid>
</mx:Application>