Flex Column Chart overlay stacking order - actionscript-3

I have a column chart in flex that has quite a few columns, the user can choose to display in column order or overlaid. Depending on the users screen it makes the chart more readable.
However, is then any call I can make to have the overlay order change depending on the data. i.e. Largest data column a the back, overlaid by the next largest so on and so fourth until the smallest column is on top.
Currently default behavior some of the small columns are obscured by the larger columns, I don't want to change alpha values to do this. (first of all thanks to flashharry! as
I have seen this question 2-3 times in some discussion forums, but not answered any where). Is this possible in flex column chart???
Any help would be immensely appreciated.
Thanks in advance..
#Serge Him
Code sample:- in the below code the profit of last two months are lesser than expense, so we cannot see the series as it is behind the expense series. I want the greater value will be always behind lesser value
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month:"Jan", Profit:2000, Expenses:1500},
{Month:"Feb", Profit:1000, Expenses:200},
{Month:"Mar", Profit:1100, Expenses:500},
{Month:"Apr", Profit:1300, Expenses:900},
{Month:"May", Profit:900, Expenses:1200},
{Month:"June", Profit:1500, Expenses:2500}
]);
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:BorderContainer width="100%" height="100%" >
<s:layout>
<s:VerticalLayout horizontalAlign="center"/>
</s:layout>
<mx:ColumnChart id="myChart" width="65%"
dataProvider="{expenses}"
showDataTips="true"
type="overlaid"
>
<mx:horizontalAxis>
<mx:CategoryAxis
dataProvider="{expenses}"
categoryField="Month"
/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries
yField="Profit"
displayName="Profit"
>
<mx:fill>
<s:SolidColor color="0x00ff00"/>
</mx:fill>
</mx:ColumnSeries>
<mx:ColumnSeries
yField="Expenses"
displayName="Expenses"
>
<mx:fill>
<s:SolidColor color="0xff0000"/>
</mx:fill>
</mx:ColumnSeries>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{myChart}"/>
<mx:DataGrid dataProvider="{expenses}" editable="true">
<mx:columns>
<mx:DataGridColumn dataField="Month" editable="true"/>
<mx:DataGridColumn dataField="Profit" editable="true"/>
<mx:DataGridColumn dataField="Expenses" editable="true"/>
</mx:columns>
</mx:DataGrid>
</s:BorderContainer>
</s:Application>

I've studied your problem, deeping in initializing ColumnChart component. There is a feature, that all columns from series is placed in separate layer. So, either green columns are on the top or red. No posibility to change parent of one column from series...I'm afraid you have to override the basic behavior of component and place all columns in the same container and sort their depths. I drew an example:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="900" height="600">
<fx:Script>
<![CDATA[
import mx.charts.series.items.ColumnSeriesItem;
import mx.collections.ArrayCollection;
[Bindable]
public var expenses:ArrayCollection = new ArrayCollection([
{Month:"Jan", Profit:200, Expenses:100, Expenses2:50},
{Month:"Feb", Profit:1000, Expenses:2000, Expenses2:500},
{Month:"Mar", Profit:1100, Expenses:500, Expenses2:100},
{Month:"Apr", Profit:1300, Expenses:900, Expenses2:1000},
{Month:"May", Profit:900, Expenses:1200, Expenses2:1000},
{Month:"June", Profit:1000, Expenses:2000, Expenses2:1500}
]);
private var items:Array = [];
private function init():void
{
items = [];
for (var i:int=0; i<myChart.series.length; i++)
{
var series:ColumnSeries = myChart.series[i] as ColumnSeries;
for (var j:int=0; j<series.items.length; j++)
{
if (!items[j])
items[j] = [];
var item:ColumnSeriesItem = series.items[j] as ColumnSeriesItem;
items[j][i] = item;
series.parent.addChild(item.itemRenderer as DisplayObject);
}
}
sort();
}
private function sort():void
{
var h:Number = myChart.height - 50;
for (var i:int=0; i<items.length; i++)
{
var group:Array = items[i];
group.sort(sortFunction);
for (var j:int=0; j<group.length; j++)
{
var item:ColumnSeriesItem = group[j] as ColumnSeriesItem;
item.itemRenderer.parent.setChildIndex(item.itemRenderer as DisplayObject, group.length - j - 1);
item.min = NaN;
if (j > 0)
item.min = h - group[j-1].itemRenderer.height;
}
}
}
private function sortFunction(item1:ColumnSeriesItem, item2:ColumnSeriesItem):int
{
var yValue1:int = item1.item[Object(item1.element).yField];
var yValue2:int = item2.item[Object(item2.element).yField];
return (yValue1 < yValue2) ? -1 : (yValue1 > yValue2) ? 1 : 0;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:BorderContainer width="100%" height="100%" >
<s:layout>
<s:VerticalLayout horizontalAlign="center"/>
</s:layout>
<mx:ColumnChart id="myChart" width="65%"
dataProvider="{expenses}"
showDataTips="true"
type="overlaid"
updateComplete="init()"
>
<mx:horizontalAxis>
<mx:CategoryAxis
dataProvider="{expenses}"
categoryField="Month"
/>
</mx:horizontalAxis>
<mx:series>
<mx:ColumnSeries
yField="Profit"
displayName="Profit"
>
<mx:fill>
<s:SolidColor color="0x00ff00"/>
</mx:fill>
</mx:ColumnSeries>
<mx:ColumnSeries
yField="Expenses"
displayName="Expenses"
>
<mx:fill>
<s:SolidColor color="0xff0000"/>
</mx:fill>
</mx:ColumnSeries>
<mx:ColumnSeries
yField="Expenses2"
displayName="Expenses2"
>
<mx:fill>
<s:SolidColor color="0xffff00"/>
</mx:fill>
</mx:ColumnSeries>
</mx:series>
</mx:ColumnChart>
<mx:Legend dataProvider="{myChart}"/>
<mx:DataGrid dataProvider="{expenses}" editable="true">
<mx:columns>
<mx:DataGridColumn dataField="Month" editable="true"/>
<mx:DataGridColumn dataField="Profit" editable="true"/>
<mx:DataGridColumn dataField="Expenses" editable="true"/>
<mx:DataGridColumn dataField="Expenses2" editable="true"/>
</mx:columns>
</mx:DataGrid>
</s:BorderContainer>
</s:Application>

Related

Flex update dataprovider after datagrid edited

I have a datagrid in flex with an itemrenderer and a dataprovider.
The problem is when I edit a datagrid, the provider don't get updated with the edited value.
Here is my datagrid:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" borderColor="#FFFFFF" cornerRadius="0">
<mx:Script>
<![CDATA[
import mx.core.Application;
[Bindable]
private var provider:ArrayCollection = new ArrayCollection([
{data:'1'},
{data:'2"}]);
]]>
</mx:Script>
<!-- Here is the data grid , the provider is groupeCollection, ihave set editable to true-->
<mx:DataGrid id="myGrid" width="100%" height="80%"
dataProvider="{provider}" x="0" editable="true" >
<mx:columns>
<mx:DataGridColumn dataField="data" >
<mx:itemRenderer>
<mx:Component>
<mx:NumericStepper minimum="1" maximum="10000" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
Now after editing the cell ( dataFiel="data" ) and printing the dataprovider, nothing changes in it.
Have not used Flex 3 since long but can you once check that whether ItemRenderer supports boolean property rendererIsEditor? If yes then set it to true then your renderer will also work as editor.
EDIT: I tried your code now and there seems to be some compiler error with delcaration of items in ArrayCollection. You seem to mix " and ' for items. I corrected it and now verified it in the below example which works. You can click the button to check before and after scenarios. I am pasting the complete code for your convenience just paste and run:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
protected function button1_clickHandler(event:MouseEvent):void
{
for(var i:int = 0; i<provider.length; i++) {
Alert.show(provider.getItemAt(i).data);
}
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" borderColor="#FFFFFF" cornerRadius="0">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.Application;
[Bindable]
private var provider:ArrayCollection = new ArrayCollection([
{data:'1'},
{data:'2'}]);
]]>
</mx:Script>
<!-- Here is the data grid , the provider is groupeCollection, ihave set editable to true-->
<mx:DataGrid id="myGrid" width="100%" height="80%"
dataProvider="{provider}" x="0" editable="true" >
<mx:columns>
<mx:DataGridColumn dataField="data" >
<mx:itemRenderer>
<mx:Component>
<mx:NumericStepper minimum="1" maximum="10000" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
<mx:Button label="Check DP" click="button1_clickHandler(event)"/>
</mx:VBox>
</mx:Application>
You can use itemEditor instead of itemRenderer, itemRenderer only show your values if you want edit the data at runtime we have set value manually by using
data.propertyname = value;
Try this code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" borderColor="#FFFFFF" cornerRadius="0">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.Application;
[Bindable]
private var provider:ArrayCollection = new ArrayCollection([
{data:'1'},
{data:'2'}]);
]]>
</mx:Script>
<mx:VBox>
<!-- Here is the data grid , the provider is groupeCollection, ihave set editable to true-->
<mx:DataGrid id="myGrid" width="100%" height="80%"
dataProvider="{provider}" x="0" editable="true" >
<mx:columns>
<mx:DataGridColumn dataField="data" editorDataField="value">
<mx:itemEditor>
<mx:Component>
<mx:NumericStepper minimum="1" maximum="10000" />
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:DataGrid width="100%" height="80%"
dataProvider="{provider}" x="0" editable="true" >
<mx:columns>
<mx:DataGridColumn dataField="data" >
<mx:itemRenderer>
<mx:Component>
<mx:NumericStepper minimum="1" maximum="10000" />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
</mx:Canvas>

Borders of AdvancedDataGrid disappears in popup

The borders of AdvancedDataGrid are disappearing. I am using the same instance of popup object to show at different times.
For the first time the popup and ADG borders are fine but when i launch the popup next time, the borders get disappeared. Though borders reappear if i try to adjust column size. I am not able to get the cause of this issue and therefore not able to rectify it either.
I tried to readjust visibility of ADG and also tried to call invalidateDisplayList(), but no success.
*ADG = AdvancedDataGrid
I am attaching code snippets.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="onCC()" width="1500" height="1000">
<s:layout>
<s:VerticalLayout />
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.advancedDataGridClasses.AdvancedDataGridSortItemRenderer;
import mx.managers.PopUpManager;
[Bindable]private var dp:ArrayCollection = new ArrayCollection();
private function onCC():void
{
var obj1:Object = new Object();
obj1.col1 = "col11";
obj1.col2 = "col12";
obj1.col3 = "col13";
dp.addItem(obj1);
obj1 = new Object()
obj1.col1 = "col21";
obj1.col2 = "col22";
obj1.col3 = "col23";
dp.addItem(obj1);
}
var popup:PopupPanel = new PopupPanel();
private function launchPopup():void
{
PopUpManager.addPopUp(popup, this as DisplayObject);
PopUpManager.centerPopUp(popup);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:AdvancedDataGrid sortableColumns="false" sortItemRenderer="{null}" dataProvider="{dp}" draggableColumns="false" >
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="PM1" dataField="col1" />
<mx:AdvancedDataGridColumnGroup headerText="PM2" >
<mx:AdvancedDataGridColumn headerText="NE" dataField="col2" />
<mx:AdvancedDataGridColumn headerText="FE" dataField="col3"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
<mx:Button label="launch popup" click="launchPopup()" />
</s:WindowedApplication>
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="1000" height="750"
close="titlewindow1_closeHandler(event)">
<s:layout>
<s:HorizontalLayout paddingLeft="20" paddingRight="20" paddingTop="20" paddingBottom="20"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.CloseEvent;
import mx.managers.PopUpManager;
[Bindable] private var dp:ArrayCollection = new ArrayCollection();
protected function titlewindow1_closeHandler(event:CloseEvent):void
{
// TODO Auto-generated method stub
PopUpManager.removePopUp(this);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:AdvancedDataGrid id="dg1" sortableColumns="false" sortItemRenderer="{null}" dataProvider="{dp}" draggableColumns="false" width="100%" height="100%">
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="PM1" dataField="col1" />
<mx:AdvancedDataGridColumnGroup headerText="PM2" >
<mx:AdvancedDataGridColumn headerText="NE" dataField="col2" />
<mx:AdvancedDataGridColumn headerText="FE" dataField="col3"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
<mx:AdvancedDataGrid id="dg2" sortableColumns="false" sortItemRenderer="{null}" dataProvider="{dp}" draggableColumns="false" width="100%" height="100%">
<mx:groupedColumns>
<mx:AdvancedDataGridColumn headerText="PM1" dataField="col1" />
<mx:AdvancedDataGridColumnGroup headerText="PM2" >
<mx:AdvancedDataGridColumn headerText="NE" dataField="col2" />
<mx:AdvancedDataGridColumn headerText="FE" dataField="col3"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
</s:TitleWindow>
I created a public method that the instance is non-null calls invalidateList() of the grid. Example:
// Update grids when the display is already instantiated
public function updates():void{
its grid.invalidateList();
}

Disable unselected items in a List After 5 items are selected

Im new to flex development. I have a dynamically data bound list component. I need to restrict user from selecting more than 5 items.
List is made with checkboxes and labels
getSelectionCount() method returns the number of currently selected items.
Here is my code
<s:VGroup width="100%" height="100%">
<s:List id="chkLst" visible="{isMultipleSelectionAllowed}" width="100%" height="100%" borderVisible="false"
fontFamily="segoeui"
dataProvider="{filteredDataSet}" >
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
//-----------------------------------------------
//
// Checkbox select
//
//-----------------------------------------------
protected function chk_clickHandler(event:MouseEvent):void
{
var selection:Array = new Array();
for each(var item:Object in outerDocument.chkLst.dataProvider)
{
selection.push(item);
}
var count:int = 0;
for each(var sItem:Object in selection)
{
outerDocument.setSelectionCount(0);
if(sItem.selected)
{
count++;
}
outerDocument.setSelectionCount(count);
}
Alert.show(outerDocument.getSelectionCount()+"","test");
if(CheckBox(event.target).selected && outerDocument.getSelectionCount() <= 5){
outerDocument.setSelectionCount(outerDocument.getSelectionCount()+1);
}
if(outerDocument.getSelectionCount() >= 6){
}
}
]]>
</fx:Script>
<s:HGroup width="100%" height="30" gap="2" paddingLeft="5" paddingRight="5" verticalAlign="middle" clipAndEnableScrolling="true">
<s:CheckBox id="chk"
label="{data.label}" change="{data.selected = chk.selected}" selected="{data.selected}"
maxWidth="215" click="chk_clickHandler(event)" />
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
How can disable the checkboxes which user has not selected when user selection count exceeds 5 ?
2 I also need to enable all check boxes back if user unticks some checks in order that selection count go below 5
Thank You
First you need to add enabled property in your arraycollection like below which also make bindable in itemRenderer enabled="{data.enabled}". If count reach 5 we disable all button except selected one which the help of enabled property and magic here we need to update arraycollection items by using mx.collections.IList.itemUpdated(item:Object, property:Object=null, oldValue:Object=null, newValue:Object=null):void method so that only it will reflect disable the other checkboxes. In our case use outerDocument.chkLst.dataProvider.itemUpdated(item);
Sample arraycollection structure:
<fx:Declarations>
<s:ArrayCollection id="filteredDataSet" >
<fx:Object selected="false" enabled="true" label="one"/>
<fx:Object selected="true" enabled="true" label="two"/>
<fx:Object selected="false" enabled="true" label="three"/>
<fx:Object selected="false" enabled="true" label="four"/>
<fx:Object selected="false" enabled="true" label="five"/>
<fx:Object selected="false" enabled="true" label="six"/>
<fx:Object selected="false" enabled="true" label="seven"/>
<fx:Object selected="false" enabled="true" label="eight"/>
<fx:Object selected="false" enabled="true" label="nine"/>
</s:ArrayCollection>
</fx:Declarations>
<s:List id="chkLst" width="100%" height="100%" borderVisible="false"
fontFamily="segoeui"
dataProvider="{filteredDataSet}" >
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function chk_clickHandler(event:MouseEvent):void
{
data.selected = chk.selected;
var selection:Array = [];
for each(var item:Object in outerDocument.chkLst.dataProvider)
{
if(item.selected)
selection.push(item);
}
if(selection.length>=5)
{
for each(var item:Object in outerDocument.chkLst.dataProvider){
item.enabled = item.selected;
outerDocument.chkLst.dataProvider.itemUpdated(item);
}
}else{
for each(var item:Object in outerDocument.chkLst.dataProvider){
item.enabled = true;
outerDocument.chkLst.dataProvider.itemUpdated(item);
}
}
}
]]>
</fx:Script>
<s:HGroup width="100%" height="30" gap="2" paddingLeft="5" paddingRight="5" verticalAlign="middle" clipAndEnableScrolling="true">
<s:CheckBox id="chk" label="{data.label}" selected="{data.selected}" enabled="{data.enabled}"
maxWidth="215" click="chk_clickHandler(event)" />
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>

How to Select All checkboxes in Flex Item Renderer?

I am stuck at a point where I need to select all check boxes of the Item Renderer.
I have a Select All button on whose click my all check boxes needs to get selected. Is it possible to do in Flex item renderer.
Below is my code for item renderer:
rowCount="2" columnCount="5" dragEnabled="false" dragMoveEnabled="false" height="100%" width="100%" verticalScrollPolicy="on" verticalScrollPosition="0" selectable="false">
<mx:itemRenderer>
<fx:Component>
<!--<mx:VBox height="100%" width="100%" verticalGap="0">-->
<mx:VBox width="175" height="200" verticalGap="0" verticalScrollPolicy="off" horizontalScrollPolicy="off" >
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.List;
import mx.core.FlexGlobals;
import mx.utils.ObjectUtil;
[Bindable]
public var productData:Array = new Array();
import mx.collections.ArrayCollection;
import mx.controls.listClasses.BaseListData;
private var _listData:BaseListData;
private var _tileList:List;
[Bindable("dataChange")]
public function get listData():BaseListData
{
return _listData;
}
public function set listData(value:BaseListData):void
{
_listData = value;
_tileList = value.owner as List;
}
override public function set data(value:Object):void
{
super.data = value;
checkFileToDownload.selected = value["isSelected"];
}
private function onChange(event:Event):void
{
data["isSelected"] = checkFileToDownload.selected;
FlexGlobals.topLevelApplication.checkFileToDownload(event);
}
/* protected function checkSelectedFile(event:MouseEvent):void
{
// TODO Auto-generated method stub
checkFileToDownload.selected = true;
FlexGlobals.topLevelApplication.generateDownloadFileArray("push",checkFileToDownload.name,checkFileToDownload.automationName);
outerDocument.downloadButtonStatus(event)
} */
]]>
</fx:Script>
<mx:HBox id="currentTileElement">
<s:CheckBox id="checkFileToDownload" name="{data.itemUrl}" automationName="{data.contentId}"
change="{onChange(event)}"
skinClass="com.skinClass.CustomCheckBoxSkin" click="{outerDocument.downloadButtonStatus(event)}"/>
<mx:TextArea wordWrap="true" fontWeight="bold" text="{data.title}" borderStyle="none" verticalScrollPolicy="off"
horizontalScrollPolicy="off" textAlign="left" editable="false"/>
</mx:HBox>
<mx:HBox>
<mx:Image source="{'/assets/'+data.contentId.substring(1, 2)+'.png'}" maintainAspectRatio="true"/>
<mx:Image id="tileListImageSource" width="150" height="75" maintainAspectRatio="false"
source="{data.localActualPath}"/>
</mx:HBox>
<!-- <mx:HBox horizontalGap="0">
<mx:Repeater id="itemCategory" dataProvider="{data.category.split('|')}">
<mx:Text textAlign="left" text="{itemCategory.currentItem}" color="#FF9900" fontWeight="bold" fontSize="9" />
</mx:Repeater>
</mx:HBox> -->
<mx:VBox horizontalGap="0" width="100%" verticalGap="0" paddingLeft="25">
<s:Spacer height="2"/>
<mx:TextArea text="{data.author.split('|')}" color="#FF9900" fontWeight="bold" chromeColor="white" height="40" editable="false" wordWrap="true" borderStyle="none" verticalScrollPolicy="on" horizontalScrollPolicy="off" textAlign="left"/>
<!-- <mx:Repeater id="authorCategory" dataProvider="{data.author.split('|')}">
<mx:Text textAlign="left" fontSize="11" fontSharpness="400" fontWeight="bold" color="#FF9900" text="{authorCategory.currentItem}"/>
</mx:Repeater> -->
<s:Spacer height="2"/>
<mx:Text fontSize="11" text="{data.publishedDate}"/>
<s:Spacer height="2"/>
<mx:HBox horizontalGap="0" verticalGap="0">
<mx:Text fontWeight="bold" fontSize="10" text="File Size: " paddingRight="0"/><mx:Text fontSize="10" color="red" paddingLeft="0" fontWeight="bold" text="{data.itemSize}MB"/>
</mx:HBox>
</mx:VBox>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:TileList>
Any help is appreciated.
Thanks,
Ankit Tanna.
You can affect all the checkboxes in your list by changing a property in the dataprovider;s objects and binding to that. Something like this in your click handler:
public function selectAllBtnClickHandler(e:MouseEvent):void {
if (selectAllBtn.selected) {
for each (var value:Object in checkboxList.dataProvider) {
value["isSelected"] = true;
}
}
}
Then change your checkbox declaration as follows:
<s:CheckBox id="checkFileToDownload" name="{data.itemUrl}" automationName="{data.contentId}"
change="{onChange(event)}" selected="{data.isSelected}"
skinClass="com.skinClass.CustomCheckBoxSkin" click="{outerDocument.downloadButtonStatus(event)}"/>
I want to clear the concept of Brian a bit , so that you can understand it better.
Here is an array collection i am using to populate the grid below
[Bindable] private var testArray:ArrayCollection = new ArrayCollection
(
[
{NAME:'Alan',DEPT:'CIS',ADDRESS:'dhaka',chk:0},
{NAME:'Jordan',DEPT:'CIS',ADDRESS:'dhaka',chk:1},
{NAME:'Simmi',DEPT:'CIS',ADDRESS:'dhaka',chk:0},
{NAME:'Alex',DEPT:'CIS',ADDRESS:'dhaka',chk:1},
{NAME:'Adams',DEPT:'CIS',ADDRESS:'dhaka',chk:0}
]
);
here goes the code of datagrid
<mx:DataGrid height="100%" width="100%" id="dataGrid" dataProvider="{testArray}">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="NAME"/>
<mx:DataGridColumn headerText="Department" dataField="DEPT"/>
<mx:DataGridColumn headerText="Address" dataField="ADDRESS"/>
<mx:DataGridColumn headerText="Address" dataField="chk">
<mx:itemRenderer>
<fx:Component>
<mx:CheckBox selected="{data.chk==1?true:false}"/>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:Button label="Check All" click="button1_clickHandler(event)"/>
Notice the item renderer which is a check box is looking on the value of "chk". You can make all the check boxes "CHECKED" by clicking "Check All" button. here is the "button1_clickHandler" function
protected function button1_clickHandler(event:MouseEvent):void
{
for(var i:int=0;i<testArray.length;i++)
{
testArray[i].chk = 1;
}
testArray.refresh();
}

Flex mx:DataGrid - Create combobox ItemRenderer

I have a mx:Datagrid in witch I'd like to add a combobox as item renderer.
<mx:DataGrid id="dgEnsActes"
horizontalScrollPolicy="on"
dataProvider="{arListeDevis}"
width="100%" height="100%" >
<mx:columns>
<mx:DataGridColumn dataField="dvIndex" headerText="" headerStyleName="dgHeader" fontWeight="normal" width="40"/>
<mx:DataGridColumn dataField="dvLibelle" headerText="Libellé" headerStyleName="dgHeader" wordWrap="true" fontWeight="normal" width="180"/>
<mx:DataGridColumn dataField="dvTotal" headerText="Total" headerStyleName="dgHeader" width="60" fontWeight="normal"/>
<mx:DataGridColumn dataField="dvStatut" headerText="Statut"
rendererIsEditor="true" editorDataField="result" itemRenderer="fr.inters.ui.itemRenderer.irComboEtatDevis"
wordWrap="true" headerStyleName="dgHeader" fontWeight="normal" width="70"/>
<mx:DataGridColumn dataField="dvAcceptDirect" headerText="Création" headerStyleName="dgHeader" width="60" fontWeight="normal"/>
</mx:columns>
</mx:DataGrid>
My custom item renderer is like that:
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<fx:Script>
<![CDATA[
public var result:String="";
[Bindable] var dpValue:Array=[
{label:"Accepté", data:"Accepté"},
{label:"Refusé", data: "Refusé"},
{label:"En attente", data: "En attente"}];
override public function set data(value:Object):void
{
super.data = value;
if (value != null)
{
var currentValue:String = value.size;
var len:int = dpValue.length;
for (var i:int = 0; i < len; i++)
{
if (dpValue[i].data == currentValue)
{
editor.selectedIndex = i;
break;
}
}
}
}
public function onChange():void
{
var index:int = editor.selectedIndex;
result = dpValue[index].data;
}
]]>
</fx:Script>
<mx:ComboBox id="editor" dataProvider="{dpValue}" width="130" change="onChange()"/>
</s:MXDataGridItemRenderer>
But when I try to debug an error appear, the message is selectedIndex is undefined
Is someone to help me?
Thanks
Why don't you use the combobox without a grid item renderer?
have a look at this sample at http://blog.flexmp.com/2008/02/18/simple-datagrid-combobox-as-item-editor-example/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:XML id="xml" source="weather.xml"/>
<mx:DataGrid id="myDatagrid" dataProvider="{xml.city}"
variableRowHeight="true" editable="true" rowHeight="50"
width="300" height="300">
<mx:columns>
<mx:DataGridColumn dataField="Location"/>
<mx:DataGridColumn dataField="Climate" editable="true" editorDataField="value">
<mx:itemEditor>
<mx:Component>
<mx:ComboBox editable="true">
<mx:dataProvider>
<mx:String>Mild</mx:String>
<mx:String>Hot</mx:String>
<mx:String>Foggy</mx:String>
<mx:String>Rainy</mx:String>
<mx:String>Snow</mx:String>
</mx:dataProvider>
</mx:ComboBox>
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="CloudCoverPercent" editable="true" editorDataField="value"
itemEditor="CloudCover"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
This is probably the best example
https://bytebucket.org/trilogy/flex-datagrid-with-dropdown-menu-combobox-item-editor/raw/0de0e1e0cd2f0bb99512aedb920eaa0d6055e359/bin/main.swf
Double Click on 2nd column
Source Code https://bitbucket.org/trilogy/flex-datagrid-with-dropdown-menu-combobox-item-editor/src