I have a Spark List and I want to show a tool tip when over a row. In the previous List I think there was a dataTipField property but I don't see that on the Spark List.
If the label displayed in the list is different than the toolTip you want to show then you can use toolTip property of the Label in Sumit's answer as below:
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script><![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var myDataProvider:ArrayCollection = new ArrayCollection([
{data:1, label:"One", desc:"Here is a toolTip description of the item One"},
{data:2, label:"Two", desc:"Here is a toolTip description of the item Two"},
{data:3, label:"Three", desc:"Here is a toolTip description of the item Three"},
{data:4, label:"Four", desc:"Here is a toolTip description of the item Four"},
{data:5, label:"Five", desc:"Here is a toolTip description of the item Five"}
]);
]]></fx:Script>
<s:List dataProvider="{myDataProvider}">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script><![CDATA[
override public function set data(value:Object):void
{
super.data = value;
}
[Bindable]
private function getToolTip():String
{
return data.desc;
}
]]></fx:Script>
<s:Label text="{data.label}" toolTip="{getToolTip()}" width="100%"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:Application>
If you want to show the tooltip when the data width is more than the List width then you can use inline itemrenderer for it.
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<s:Label text="{data.Expense}"
width="100"
maxDisplayedLines="1"
showTruncationTip="true" />
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
Related
I have a ComboBox in Flex which is listing like this:
A-B-C-D-E-F
A-B-C-D-E-F-*
A-B-C-D-E-F-G-*
A-B-C-D-E-F-*
I want to make the * appear red. Could anyone help me regarding this?
Hopefully self-explaining:
<s:ComboBox itemRendererFunction="getItemRenderer"
dataProvider="{new ArrayList(['A-B-C-D-E-F', 'A-B-C-D-E-F-', 'A-B-C-D-E-F-G-', 'A-B-C-D-E-F-'])}"/>
<fx:Declarations>
<fx:Component className="RedItemRenderer">
<s:ItemRenderer>
<s:HGroup verticalAlign="middle">
<s:Label text="{data}" color="red" paddingLeft="3" paddingRight="3" paddingTop="5" paddingBottom="5"/>
<s:Image source="#Embed(source='warning.png')"/>
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</fx:Declarations>
<fx:Script><![CDATA[
import mx.collections.ArrayList;
import spark.skins.spark.DefaultItemRenderer;
private function getItemRenderer(item:Object):IFactory
{
var s:String = item as String;
if (s.charAt(s.length-1) == '-')
return new ClassFactory(RedItemRenderer);
else
return new ClassFactory(DefaultItemRenderer);
}
]]></fx:Script>
This is how it looks like:
I have a data grid table, the gridColumn in the dataGrid table calls a "DropDownListItemRenderer". Using the same item renderer I want to change the contents in the drop down list according to the dataField name. So for example if the dataField name is colour then the drop down will contain red,blue,green ect. If the dataField name is furits, then the drop down list will contain different fruits options.
If u look at the codes in my item Renderer. I tried to do the above by creating a bindable array collection called dropDownListData. In the override set data function I get the dataField name, Using the data field name I add items in array collection accordingly.
Although the dropdown list is filled with the correct data when u run the program. The data in the drop down list is repeated and increased every time when the dropdown list is selected.
I think I am not using the right method to do this. So can someone show me how I do this ? Pls can someone help me with this ? Pls let me know if my question is not clear I will try to rephrase it.
Thanks :)
This is my MXML file :
<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:Script>
<![CDATA[
import FrontEndObjects.ColourItems;
import mx.collections.ArrayCollection;
import spark.events.IndexChangeEvent;
[Bindable]
private var order:ArrayCollection = new ArrayCollection();
private function addOrder():void{
var orderItems:ColourItems = new ColourItems();
order.addItem(orderItems);
}
]]>
</fx:Script>
<s:BorderContainer x="175" y="101" width="606" height="289">
<s:DataGrid id="myDG" x="53" y="27" width="516" height="201" dataProvider="{order}"
editable="true" variableRowHeight="true">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="label1" headerText="Order #" editable="true"/>
<s:GridColumn dataField="quant" headerText="Qty" editable="true"/>
<s:GridColumn dataField="color" headerText="Color" editable="true" rendererIsEditable="true" itemRenderer="myRenderers.DropDownListItemRenderer"/>
<s:GridColumn dataField="furits" headerText="Furits" editable="true" rendererIsEditable="true" itemRenderer="myRenderers.DropDownListItemRenderer"/>
</s:ArrayList>
</s:columns >
</s:DataGrid>
<s:Button x="499" y="236" label="add" click="addOrder()" />
</s:BorderContainer>
This is my DropDownList item Renderer :
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import spark.components.gridClasses.GridColumn;
import spark.events.IndexChangeEvent;
public var cName:String;
[Bindable]
private var dropDownListData:ArrayCollection = new ArrayCollection();
protected function onCbChange(event:IndexChangeEvent):void
{
var value:String = (event.currentTarget as DropDownList).selectedItem;
data[column.dataField] = value;
}
override public function set data(value:Object):void
{
super.data = value;
cName = column.dataField;
if(cName == "color"){
dropDownListData.addItem("red");
dropDownListData.addItem("blue");
dropDownListData.addItem("green");
}
else if(cName == "furits"){
dropDownListData.addItem("banana");
dropDownListData.addItem("apple");
dropDownListData.addItem("grapes");
}
}
]]>
</fx:Script>
<s:DropDownList id="cb" width="100%" change="onCbChange(event)" requireSelection="true" dataProvider="{dropDownListData}"/>
This is my Object class :
public class ColourItems
{
public var label1:String;
public var quant:String;
public var color:String;
public var furits:String;
}
In the setData method of the itemRenderer, you should check what data already exists in the list before doing the addItem
You set target columns as editable: editable="true" rendererIsEditable="true". When you click for cell, grid calls set data(value:Object) method in itemrenderer where you add items in dropdown list more more and more. You can easy fix it as disabled editable for cell:
<s:GridColumn dataField="color" headerText="Color" editable="false" itemRenderer="myRenderers.DropDownListItemRenderer"/>
<s:GridColumn dataField="furits" headerText="Furits" editable="false" itemRenderer="myRenderers.DropDownListItemRenderer"/>
I have a DataGrid with the first column being strings ("Red", "Blue", etc) and the second column being a circle (custom UIComponent) of the corresponding color. If I click on the first column to sort, all the names of the colors are sorted fine but those circles in the second column are in totally wrong order. Anyone knows what went wrong with the code below?
This is the application 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"
xmlns:components="components.*"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myArray:ArrayCollection = new ArrayCollection([
{ name:"Red", color:0xff0000 },
{ name:"Orange", color:0xff8000 },
{ name:"Yellow", color:0xffff00 },
{ name:"Green", color:0x00ff00 },
{ name:"Blue", color:0x0000ff },
{ name:"Purple", color:0xff00ff }
]);
]]>
</fx:Script>
<s:DataGrid dataProvider="{myArray}">
<s:columns>
<s:ArrayCollection>
<s:GridColumn dataField="name"/>
<s:GridColumn dataField="color">
<s:itemRenderer>
<fx:Component>
<s:GridItemRenderer>
<s:VGroup>
<components:Circle color="{data.color}" />
</s:VGroup>
</s:GridItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:GridColumn>
</s:ArrayCollection>
</s:columns>
</s:DataGrid>
</s:Application>
And this is the custom UIComponent:
package components
{
import mx.core.UIComponent;
public class Circle extends UIComponent
{
public var color:uint;
public function Circle()
{
super();
height = 20;
width = 20;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledWidth);
graphics.clear();
graphics.beginFill(color, 1);
graphics.drawCircle(10, 10, 8);
graphics.endFill();
}
}
}
Your custom component is probably simply not redrawn. The easiest solution to this is to not use a custom component at all and use FXG graphics to draw your circle instead.
Replace your itemrenderer with this one and it should work fine:
<s:GridItemRenderer>
<s:Ellipse width="20" height="20">
<s:fill>
<s:SolidColor color="{data.color}" />
</s:fill>
</s:Ellipse>
</s:GridItemRenderer>
That said, I would put the label and the color sample in one column (instead of two) since they represent the same data.
I have a spark List,its item renderer is a panel,and in the panel there are some components such as Textinput,now I want to drag and drop a panel within the List,how can I do that,could you pls show me the code,thanks.
The list in flex has a default drag and drop functionality. So basically all you need to do is to set 3 properties to true to your list:
dragMoveEnabled, dragEnabled and dropEnabled. So your list if you add it from mxml will look like this:
<s:List dataProvider="{yourDataProvider}" dragMoveEnabled="true" dragEnabled="true" dropEnabled="true" />
For more details about these 3 properties you can check the spark list documentation:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/List.html#dragMoveEnabled
thanks for your help.Now I catch an error while draging the itemRenderer(my flex sdk is 4.5.1).
My list itemRenderer:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer 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="100%" height="100%">
<fx:Script>
<![CDATA[
import mx.events.CloseEvent;
override public function set data(value:Object ) : void{
super.data = value;
}
protected function closeHandler(event:CloseEvent):void
{
//ToDo
}
]]>
</fx:Script>
<s:TitleWindow x="0" y="0" title="{data.label}"
width="100%" height="100%" creationPolicy="all"
skinClass="skin.titleWindowSkin"
close="closeHandler(event)">
<s:Label text="{data.value}"/>
<s:TextInput x="123" y="58" text="#{data.value}"
focusIn="parentDocument.owner.dragEnabled=false"
focusOut="parentDocument.owner.dragEnabled=true"/>
</s:TitleWindow>
</s:ItemRenderer>
While draging,catch an error like:
Error: Skin for DragProxy261.ListItemDragProxy260.DspDesktopItemRenderer262._DspDesktopItemRenderer_TitleWindow1.titleWindowSkin264.Group265.contents._titleWindowSkin_Group5.contentGroup._DspDesktopItemRenderer_TextInput1 cannot be found.
at spark.components.supportClasses::SkinnableComponent/attachSkin()[E:\dev\4.5.1\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableComponent.as:698]
In Flex 3, it used to be possible to bind a component property within an itemRenderer via outerDocument. So for instance, if there was a image inside an itemRenderer that was only displayed on a given condition of the parent, something like this would work perfectly:
<mx:itemRenderer>
<mx:Component>
<mx:Label text="{data}"/>
<mx:Image id="img" visible="{outerDocument.ShowImage}" includeInLayout="{outerDocument.ShowImage}"/>
</mx:Component>
</mx:itemRenderer>
where the outer document (not the list, but the mxml the list is in) contained something like
[Bindable]
public function get ShowImage():void
{
return showImage;
}
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
I've tried to do the same thing in Flex 4.5 using Spark item renderers using parentDocument, but it doesn't seem to be aware to the binding. When I do this in Flex 4.5, the itemRenderer doesn't seem to be aware when the parentDocument ShowImage changes.
Has anyone seen this issue and is able to offer a solution?
EDIT: Add Spark Source
As requested here is my spark source:
MyItemRenderer.mxml
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:Label id="myLabel" text="{data}/>
<s:Image src="something.png" visible="{parentDocument.ShowImage}" includeInLayout="{parentDocument.ShowImage}"/>
</s:ItemRenderer>
RendererContainer.mxml
<s:Panel 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[
private var showImage:Boolean = false;
[Bindable]
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
public function get ShowImage():Boolean
{
return showImage;
}
]]>
</fx:Script>
<!-- Content Group -->
<s:List id="lstCell" width="100%" height="100%" itemRenderer="MyItemRenderer">
</s:List>
</s:Panel>
Ok so there is a checkbox in a wrapper outside of RendererContainer.mxml that dispatches a custom event that is handled by changing a Bindable Boolean. The change in that var then changes the ShowImage property on my RendererContainer component. I would expect that the binding would then be picked up by MyItemRenderer but it doesnt seem to be working.
So my outer wrapper would access ShowImage like this
<comp:RendererContainer id="myId" ShowImage="{myCheckbox.selected}"/>
I think this should do the trick for you, YourTypeHere would be the class of the containing
object, make sure the ShowImage property is public and bindable.
<mx:itemRenderer>
<mx:Component>
<mx:Script>
<![CDATA[
import YourTypeHere;
]]>
</mx:Script>
<mx:Label text="{data}"/>
<mx:Image id="img"
visible="{YourTypeHere(this.parent.ShowImage)}"
includeInLayout="{YourTypeHere(this.parent.ShowImage)}"/>
</mx:Component>
</mx:itemRenderer>
P.s. please don't name properties with a starting uppercase letter, including getters, consider naming it showImage and your private var to something like _showImage instead :D
Your getter seems to have return type as void. Change that to Boolean
[Bindable]
public function get ShowImage():Boolean
{
return showImage;
}
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
This will help.
<s:Image src="something.png" visible="{RendererContainer(ListSkin(parentDocument).parentDocument).ShowImage}" includeInLayout="{RendererContainer(ListSkin(parentDocument).parentDocument).ShowImage}"/>
Following works perfectly fine:
<?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">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
private var showImage:Boolean = false;
[Bindable]
public function set ShowImage(val:Boolean):void
{
showImage = val;
}
public function get ShowImage():Boolean
{
return showImage;
}
]]>
</fx:Script>
<s:CheckBox label="Select" change="{ShowImage = !ShowImage}"/>
<!-- Content Group -->
<s:List id="lstCell" width="100%" height="100%" dataProvider="{new ArrayCollection(['A','B'])}">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:Label id="myLabel" text="{data}"/>
<s:Button label="something.png" visible="{outerDocument.ShowImage}" includeInLayout="{outerDocument.ShowImage}"/>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
</s:Panel>
</s:WindowedApplication>