I have a .mxml file which has following Panel
<s:Panel width="130%" height="100%" title="Results {noOfRowsText}">
<s:layout>
<s:VerticalLayout paddingTop="5" paddingLeft="5" paddingBottom="5" paddingRight="5"/>
</s:layout>
<mx:DataGrid id="desResults" width="100%" height="100%" dataProvider="{response.sList}"
visible="{response != null && response.sList != null && response.sList.length != 0}"
itemClick="datagrid_itemClickHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="Start Date" dataField="sVaRWindowStartDate"
itemRenderer="com.vanilla.package.class"/>
<mx:DataGridColumn headerText="End Date" dataField="sVaRWindowEndDate"
itemRenderer="com.vanilla.package.class"/>
<mx:DataGridColumn headerText="Value" dataField="Value" textAlign="left"
itemRenderer="com.vanilla.package.classOne"/>
<mx:DataGridColumn headerText="Description" dataField="description" textAlign="right"
itemRenderer="com.vanilla.package.classOne"/>
</mx:columns>
</mx:DataGrid>
</s:Panel>
<s:Panel id="panelLsR" width="60%" height="100%" includeIn="lsr" title="LsR Details">
<s:layout>
<s:VerticalLayout horizontalAlign="left"
verticalAlign="top" paddingTop="5"
paddingLeft="5" paddingRight="5" paddingBottom="5"/>
</s:layout>
<s:HGroup width="100%" verticalAlign="middle" horizontalAlign="left" gap="10">
<mx:Text text="{lsrPanelTitle}"/>
<mx:Spacer width="100%"/>
<s:Button label="Close" click="lsrPanel_closeHandler(event)"/>
</s:HGroup>
<mx:DataGrid id="lsrResults" width="100%" height="100%"dataProvider="{lsrSeriesList}"
visible="{lsrSeriesList != null && lsrSeriesList.length != 0}"
itemClick="datagrid_itemClickHandler(event)">
<mx:columns>
<mx:DataGridColumn headerText="Date" dataField="date"/>
<mx:DataGridColumn headerText="Value" dataField="value" textAlign="right" itemRenderer="com.vanilla.package.class"/>
</mx:columns>
</mx:DataGrid>
</s:Panel>
When I click on the end Date column, the screen gets divided into two parts, one for Results (noOfRows) and other for lsrDetails. I want to decrease the width for lsrDetails part and want to increase the width for Results (noOfRows). How can I achieve this? datagrid_itemClickHandler function as follow. I tried to change the width percentages in the panelLsR but no luck. Can somebody please help me achieve this? I am working on flex for the first time.
protected function datagrid_itemClickHandler(event:ListEvent):void
{
getsLsR(request);
}
To resize the panel using percentage width, use 'percentWidth'. For example:
panelsLsr.percentWidth = 80;
Also, fix the other panel width so that it adds up to 100%.
I am creating nested data grid using flex, I have different columns for each level(refer screenshot). But its rendering new data grid for each column.
Here is my mxml
<?xml version="1.0" encoding="utf-8"?>
<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"
minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var dpHierarchy:ArrayCollection = new ArrayCollection([
{Country:"INDIA", Category:"Developing Country" ,Population:100000000,
children: [
{State:"Andhra", Language:"Telugu", SoilColor:"Red",
children:[
{District:"GUNTUR", HeadQuaters:388865, Crops:"Tobacco"},
{District:"Vijayawada", HeadQuaters:388865, Crops:"rice"}
] },
{State:"Karnataka", Language:"Kannada", SoilColor:"Black",
children:[
{District:"Mysore", HeadQuaters:388865, Crops:"Mirchi"},
{District:"Mandya", HeadQuaters:388865, Crops:"Vegetables"}
] }
] },
{Country:"KOREA", Category:"UnDeveloping Country", Population:100000000,
children:[
{State:"fgff", Language:"fggff", SoilColor:"Red",
children: [
{District:"fgdfgfg", HeadQuaters:388865, Crops:"Tobacco"},
{District:"gfgdfgfg", HeadQuaters:388865, Crops:"rice"}
] },
{State:"fgfgdfg", Language:"gdfgdfg", SoilColor:"Black",
children:[
{District:"ggff", HeadQuaters:388865, Crops:"Mirchi"},
{District:"gfgfgfg", HeadQuaters:388865, Crops:"Vegetables"}
] }
] }
]);
]]>
</fx:Script>
<mx:AdvancedDataGrid width="100%" height="100%" variableRowHeight="true">
<mx:dataProvider>
<mx:HierarchicalData source="{dpHierarchy}"/>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Country" headerText="Country"/>
<mx:AdvancedDataGridColumn dataField="Category" headerText="Category"/>
<mx:AdvancedDataGridColumn dataField="Population" headerText="Population"/>
<mx:AdvancedDataGridColumn dataField="children" headerText="children"/>
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider columnIndex="1" columnSpan="4" depth="2"
renderer="InnerGrid"/>
<mx:AdvancedDataGridRendererProvider columnIndex="2" columnSpan="3" depth="3"
renderer="InnerChildGrid"/>
</mx:rendererProviders>
</mx:AdvancedDataGrid>
</s:Application>
Here is my custom renderer [InnerGrid.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid 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="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
override public function set data(value:Object):void {
this.dataProvider = value;
}
]]>
</fx:Script>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="State" headerText="State"/>
<mx:AdvancedDataGridColumn dataField="Language" headerText="Language"/>
<mx:AdvancedDataGridColumn dataField="SoilColor" headerText="SoilColor"/>
</mx:columns>
</mx:AdvancedDataGrid>
Here is my custom renderer [InnerChildGrid.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid 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="400" height="300">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
override public function set data(ivalue:Object):void {
this.dataProvider = ivalue.Districts;
}
]]>
</fx:Script>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="District"/>
<mx:AdvancedDataGridColumn dataField="HeadQuaters"/>
<mx:AdvancedDataGridColumn dataField="Crops"/>
</mx:columns>
</mx:AdvancedDataGrid>
I solved the problem, I am attaching the code for someone to refer in future
[Application mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.collections.HierarchicalData;
private var masterData:Array = [
{ OrderId: 10248, CustomerId:"WILMK", EmployeeId:5, OrderDate:"1-Feb-2007",
children:[
[
{ProductId:11, ProductName:"Quesbo Cabrales", UnitPrice:14, Quantity:12, Discount:0, Price:168, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]},
{ProductId:42, ProductName:"Singaporean Hokkien Fried Mee", UnitPrice:9.8, Quantity:10, Discount:0, Price:98, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]},
{ProductId:42, ProductName:"Mozzarella di Giovanni", UnitPrice:34.8, Quantity:5, Discount:0, Price:174, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]}
]
]},
{ OrderId: 10249, CustomerId:"TRADH", EmployeeId:6, OrderDate:"3-Feb-2007",
children:[
[
{ProductId:51, ProductName:"Manjimup Dried Appels", UnitPrice:42.4, Quantity:40, Discount:0, Price:1696, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]},
{ProductId:14, ProductName:"Tofu", UnitPrice:18.6, Quantity:9, Discount:0, Price:167.4, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]}
]
]},
{ OrderId: 10250, CustomerId:"HANAR", EmployeeId:4, OrderDate:"4-Feb-2007",
children:[
[
{ProductId:51, ProductName:"Manjimup Dried Appels", UnitPrice:42.4, Quantity:35, Discount:0.15, Price:1261, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]},
{ProductId:41, ProductName:"Jack's Clam Chowder", UnitPrice:7.7, Quantity:10, Discount:0, Price:77, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]},
{ProductId:65, ProductName:"Hot pepper Sauce", UnitPrice:16.8, Quantity:10, Discount:0.15, Price:214.2, children:[[{count:"28",place:"HYD",Amount:"1234"},{count:"28",place:"HYD",Amount:"1234"}]]}
]
]}
];
]]>
</mx:Script>
<mx:AdvancedDataGrid dataProvider="{new HierarchicalData(masterData)}" variableRowHeight="true" width="600" height="600">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="OrderId" headerText="Ordere ID" width="100"/>
<mx:AdvancedDataGridColumn dataField="CustomerId" headerText="Customer ID" />
<mx:AdvancedDataGridColumn dataField="EmployeeId" headerText="Employee ID" />
<mx:AdvancedDataGridColumn dataField="OrderDate" headerText="Order Date" />
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider depth="2" columnIndex="1" renderer="DetailGrid" columnSpan="0" />
</mx:rendererProviders>
</mx:AdvancedDataGrid>
</mx:Application>
[DetailGrid.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid xmlns="*" variableRowHeight="true" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.HierarchicalData;
override public function set data(value:Object):void
{
dataProvider=new HierarchicalData(value);
this.rowCount = value.length+5;
// dataProvider = value;
}
]]>
</mx:Script>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="ProductId" headerText="Product ID" />
<mx:AdvancedDataGridColumn dataField="ProductName" headerText="Product Name" />
<mx:AdvancedDataGridColumn dataField="UnitPrice" />
<mx:AdvancedDataGridColumn dataField="Discount" />
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider depth="2" columnIndex="1" renderer="InnerDetailGrid" columnSpan="5" />
</mx:rendererProviders>
</mx:AdvancedDataGrid>
[InnerDetailGrid.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid xmlns="*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
override public function set data(value:Object):void
{
dataProvider = value;
this.rowCount = value.length+1;
}
]]>
</mx:Script>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="count" headerText="count" />
<mx:AdvancedDataGridColumn dataField="place" headerText="place" />
<mx:AdvancedDataGridColumn dataField="Amount" headerText="Amount" />
</mx:columns>
</mx:AdvancedDataGrid>
Here is the final o/p
I need your help on following.
I have one datagrid which use an arraylist as a data provider. Now my requirment is in that arraylist i have one statusId as one variable or say property which i display as one of the column in datagrid. now i have another column where i have to display three links like edit, delete and view which will be based on the statusid. can you give me some idea or example
I'm no Flex expert, but usually when you want to customise the appearance of a column in a DataGrid you use an ItemRenderer, as indicated by your tag. Within the item renderer, you could use Label components and set a selection of attributes that make them look like links, and then enable/disable them depending on your condition.
Here's some example code off the top of my head, with the following caveats:
I'm using an MX DataGrid instead of the Spark DataGrid.
I'm using an inline item renderer for convenience, but it is better practice to externalise your item renderers into separate MXML files.
<mx:DataGrid id="dataGrid" dataProvider="{dataProvider}" ...>
<mx:columns>
<mx:DataGridColumn id="status_id_column" dataField="statusId" headerText="Status" />
<mx:DataGridColumn id="action_column">
<mx:itemRenderer>
<fx:Component>
<mx:Label text="View" paddingLeft="10" useHandCursor="true" buttonMode="true" mouseChildren="false" enabled="Your condition goes here" />
<mx:Label text="Edit" paddingLeft="10" useHandCursor="true" buttonMode="true" mouseChildren="false" enabled="Your condition goes here" />
<mx:Label text="Delete" paddingLeft="10" useHandCursor="true" buttonMode="true" mouseChildren="false" enabled="Your condition goes here" />
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
thanks avik for your help it is partially correct as for me there are lot of condition i can not put that in enabled attribute. anyway i got the solution from my side :)
here is the syntax.
<mx:HBox width="100%">
<mx:DataGrid id="reportDataGrid" dataProvider="{reportDataGridArrayCollection}"
variableRowHeight="true" editable="false" rowHeight="75"
width="100%" height="400" allowDragSelection="false"
draggableColumns="false" textAlign="center">
<mx:columns>
<mx:DataGridColumn sortable="false" dataField="reportId" resizable="false" headerText="" width="0.06" editable="false" textAlign="center"/>
<mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="reportStatusId" headerWordWrap="true" headerText="Status" width="0.21">
</mx:DataGridColumn>
<mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="lockedByUser" headerWordWrap="true" headerText="Locked (Worked) By" width="0.10"/>
<mx:DataGridColumn resizable="false" headerStyleName="centered" textAlign="left" dataField="" headerWordWrap="true" headerText="Acion" width="0.20">
<mx:itemRenderer>
<fx:Component>
<mx:HBox textAlign="left" width="100%" creationComplete="init1()" >
<fx:Script>
<![CDATA[
public function init1():void {
if(data.reportStatusId==0) {
viewLnk.visible = true;
viewLnk.includeInLayout = true;
// this is my condition which you can ignore.... if((data.entityId==1 || data.entityId==2 || data.entityId==3 || data.entityId==4) ){
editLnk.visible = true;
editLnk.includeInLayout = true;
}
}
if(data.reportStatusId==1
) {
editLnk.visible = true;
editLnk.includeInLayout = true;
}
if(data.reportStatusId==2) {
reviewLnk.visible = true;
reviewLnk.includeInLayout = true;
}
if(data.reportStatusId==3) {
saveXMLLnk.visible = true;
saveXMLLnk.includeInLayout = true;
}
}
]]>
</fx:Script>
<mx:LinkButton id="editLnk" visible="false" includeInLayout="false" label="Edit" click="outerDocument.editReport(data.reportId)"/>
<mx:LinkButton id="viewLnk" visible="false" includeInLayout="false" label="View" click="outerDocument.viewReport(data.reportId)"/>
<mx:LinkButton id="reviewLnk" visible="false" includeInLayout="false" label="Review" click="outerDocument.reviewReport(data.reportId)"/>
<mx:LinkButton id="saveXMLLnk" visible="false" includeInLayout="false" label="Save XML" click="outerDocument.saveXMLReport(data.reportId)"/>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:HBox>
i have this code
<mx:DataGrid id="tempListDG" itemDoubleClick="doubleClickHandler(event)" width="100%" height="100%" rowHeight="110"
draggableColumns="false" sortableColumns="false" allowMultipleSelection="false">
<mx:columns>
<mx:DataGridColumn id="chkSel" headerText=" " width="15" sortable="false">
<mx:itemRenderer>
<mx:Component>
<mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off" paddingLeft="3">
<mx:Script>
<![CDATA[
]]>
</mx:Script>
<mx:CheckBox name="chkSel" selected="false" />
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn id="sum" dataField="#summary" headerText="Summary Description" width="280" >
<mx:itemRenderer>
<mx:Component>
<mx:HBox name="thumbs" creationComplete="setThumbnailImage(event)" verticalAlign="top" verticalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.controls.Text;
import com.azaaza.containers.HBox;
import com.azaaza.controls.Image;
import com.hwakin.tavi.model.ModelLocator;
import mx.controls.DataGrid;
private function setThumbnailImage(e:Event):void{
var dg:DataGrid = DataGrid(e.target.parent.parent);
var dCounter:int = TemplateOpenPanel(dg.parent.parent).dCount;
if (dCounter+1 > XMLList(dg.dataProvider).length()){
dg.validateDisplayList();
return;
}
img.load(ModelLocator.getInstance().StringToBitmap(XMLList(dg.dataProvider)[dCounter].#thumbStr));
img.width = 80;
img.height = 110;
txt.htmlText = XMLList(dg.dataProvider)[dCounter].#summary;
txt.maxHeight = 110;
dCounter++;
TemplateOpenPanel(dg.parent.parent).dCount = dCounter;
}
]]>
</mx:Script>
<mx:Image id="img">
</mx:Image>
<mx:Text id="txt">
</mx:Text>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="#dateCreated" headerText="Date Created" width="100" />
<mx:DataGridColumn dataField="#dateModified" headerText="Date Modified" width="100"/>
<mx:DataGridColumn dataField="#guid" headerText="guid" visible="false"/>
<mx:DataGridColumn dataField="#fileName" headerText="File Name" visible="false"/>
<mx:DataGridColumn dataField="#tempXml" headerText="tempXml" visible="false"/>
</mx:columns>
</mx:DataGrid>
the datagridcolumn id named "sum" creates images and text given by the XML i loaded
but i got error when i use the scroll of the datagrid. and the images get disaligned and all of the data like the dateCreated and dateModified are shuffled or something.
please help me with this one.. thanks
If you are still looking for answer add this into your code.
1)
protected function dgtempListDG_scrollHandler(event:ScrollEvent):void
{
// TODO Auto-generated method stub
tempListDG.invalidateDisplayList();
}
2)
scroll = "dgtempListDG_scrollHandler(event)"
Add this in mx:datagrid.
remember that item renderers are recycled and reused, so you should not use creationCompelte events, (if only 5 item renderers are visible, only 7 are created and then they are reused, but they are created only once so creation complete only fires once)
I like to use dataChange events, they work upon creation and each time the data of the itemRenderer changes.
I have a chechbox in a gridview. i need it disabled for some condition and enabled for other.
Problem is how to fetch check box id out side the grid.
Please help ....
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:pw="http://intelligentpathways.com.au/Flex/v2">
<mx:ArrayCollection id="ac">
<mx:Object name="Alpha" enabled="{true}"/>
<mx:Object name="Bravo" enabled="{true}"/>
<mx:Object name="Charlie" enabled="{false}"/>
<mx:Object name="Delta" enabled="{false}"/>
<mx:Object name="Echo" enabled="{true}"/>
</mx:ArrayCollection>
<mx:Panel horizontalCenter="0" verticalCenter="0" title="Renderer Demo">
<mx:DataGrid width="500" height="300" dataProvider="{ac}">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name"/>
<mx:DataGridColumn headerText="Enabled?" dataField="enabled"/>
<mx:DataGridColumn headerText="Checkbox">
<mx:itemRenderer>
<mx:Component>
<mx:Box paddingLeft="3">
<mx:CheckBox label="Foxtrot" enabled="{data.enabled}"/>
</mx:Box>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:Application>
By giving you're check box an ID you should be able to reference it no matter what container objects it's it.
<mx:CheckBox id=myCheckbox ... />
can then be referenced in any script in that file like this:
private function toggleCheckBoxEnabled():void{
if(some condition){
myCheckBox.enabled = true;
}else{
myCheckBox.enabled = false;
}
}