A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: how to restrict editable datagrid values in flex ??

  1. #1
    Senior Member
    Join Date
    Jun 2009
    Posts
    101

    Thumbs up how to restrict editable datagrid values in flex ??

    Hello Friends,

    I need a small help in Flex_DataGrid.

    I have a datagrid in flex and i am making the datagrid as editable. I can able to edit it and enter the values. so far so good. Now my requirement was, i want to restrict the editable datagrid cell to some max chars like 10. I mean to say maxChars = 10, i want to restrict like this & i want to implement like this. how is this possible.

    i need a solution asap.

    Rajesh

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You create an renderer. Here is a sample script for the Datagrid:
    PHP Code:
    <?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>
            <fx:Model id="itemData" source="data/numbers.xml"/>
            <s:ArrayList id="itemAC" source="{itemData.row}"/>
        </fx:Declarations>
        <mx:DataGrid id="myGrid" editable="true"
                     dataProvider="{itemAC}">
            <mx:columns>
                <mx:DataGridColumn dataField="item" headerText="Item"/>
                <mx:DataGridColumn dataField="number" headerText="Number" 
                                   itemRenderer="renderers.MaxNumRenderer"/>
            </mx:columns>
        </mx:DataGrid>
    </s:Application>
    This is the xml file in a package called data:
    PHP Code:
    <?xml version="1.0"?>
    <numbers>
        <row>
            <item>xx</item>
            <number>2</number>
        </row>
        <row>
            <item>yy</item>
            <number>3</number>
        </row>
        <row>
            <item>zz</item>
            <number>4</number>
        </row>
     </numbers>
    And this is the item renderer MaxNumRenderer in a package called renderers:
    PHP Code:
    <?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"
                              dataChange="updateHTML()">
        <fx:Script>
            <![CDATA[
                private function updateHTML():void
                {
                    if(int(lblData.text) > 5)
                    {
                        lblData.text = "5";
                    }
                }
            ]]>
        </fx:Script>
        <s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{dataGridListData.label}" />
    </s:MXDataGridItemRenderer>
    When you now change the number and it is larger than 5, the number will automatically go back to 5.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    If you want to limit the number of characters then use this in the renderer:

    if(lblData.text.length > 10)
    {
    lblData.text = "10 is max";
    }
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center