开发者

Custom component dataGrid selectionMode as a property

I have a custom component of which have a advancedDataGrid inside it. I want this component to be reusable so need is set the datagid selectionMode as a component property.

In mxml i want set property like this:

<comp:MyComp itemDataGridSelectionMode="singleCell" .../>

Inside MyComp actionScript i have a metatag like this:

[Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
public var itemDataGridSelectionMode:String;

How do i bind this itemDataGridSelectionMode variable to advancedDatagrid selectionMode?

UPDATE: Here is a small test application fully working code:

<!--MyComp.mxml-->
<?xml version="1.0" enco开发者_运维问答ding="utf-8"?>
<s:Group 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="638" height="500">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        [Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
        public function set itemsSelectionMode(value:String):void
        {
            this.adgItems.selectionMode = value;
        }

        public function get itemsSelectionMode():String
        {
            return this.adgItems.selectionMode;
        }
    ]]>
</fx:Script>
<mx:AdvancedDataGrid id="adgItems" designViewDataType="flat" width="100%" height="100%">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="Column 1" dataField="col1"/>
        <mx:AdvancedDataGridColumn headerText="Column 2" dataField="col2"/>
        <mx:AdvancedDataGridColumn headerText="Column 3" dataField="col3"/>
    </mx:columns>
</mx:AdvancedDataGrid>
</s:Group>

<!-- 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" minWidth="955" minHeight="600" xmlns:comp="*">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<comp:MyComponent x="272" y="86" itemsSelectionMode="singleCell"/>
</s:Application>

Error: Invalid value: multipleRows. It must be one of singleRow, multipleRows, singleCell, multipleCells.


Where you have your public var within your custom component, do this:

[Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
public function set itemDataGridSelectionMode(value:String):void
{
   advancedDatagrid.selectionMode = value;
}

public function get itemDataGridSelectionMode():String
{
   return advancedDatagrid.selectionMode;
}


I guess you can set the itemDataGridSelectionMode as [Bindable] and then can bind it with the selectionMode property of the AdvancedDataGrid.


One way is:

BindingUtils.bindProperty(datagridId, 'selectionMode', this, itemDataGridSelectionMode);

OR Use a setter method instead of variable definition.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜