4 Replies Latest reply on Aug 17, 2011 4:59 AM by Vibhuti Gosavi(InfoCepts)

    how to restrict a particular column values in a datagrid in flex4 app

    Venkatesan Balasubramanian Level 1

      hi friends,

       

      i am using a datagrid with 3 columns. Already i entered stings in first two columns,now i want to restrict the 3rd,it should allow numbers only,

       

      do not accept characters and special characters,

       

       

       

      how to restrcit a particular column value,

       

      any suggession or snippet code are welcome

       

      Thanks,

      B.venkatesan

        • 1. Re: how to restrict a particular column values in a datagrid in flex4 app
          miguel8312 Level 3

          put an item renderer in the column and then put a validator on the it

          em renderer.

          miguel

          • 2. Re: how to restrict a particular column values in a datagrid in flex4 app
            Vibhuti Gosavi(InfoCepts) Level 3

            Hi,

             

            Following code may help you.

             

            <?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 -->

            <s:NumberValidator id="validate" source="{txt}" property="text"  domain="int" />

            </fx:Declarations>

             

            <fx:Script>

            <![CDATA[

            import mx.collections.ArrayCollection;

            [Bindable]

            public var arr:ArrayCollection=new ArrayCollection([{A1:"aaa" , B1: "bbb"}]);

             

            ]]>

            </fx:Script>

            <s:DataGrid id="Dg1" x="67" y="97" width="379" editable="true"  dataProvider="{arr}" >

            <s:columns>

            <s:ArrayList>

            <s:GridColumn dataField="A1" headerText="Column 1"></s:GridColumn>

            <s:GridColumn  dataField="B1" headerText="Column 2"></s:GridColumn>

            <s:GridColumn id="col"  headerText="Column 3"  >

            <s:itemRenderer>

            <fx:Component>

            <s:GridItemRenderer>

            <s:TextInput id="txt"/>

            </s:GridItemRenderer>

            </fx:Component>

            </s:itemRenderer>

            </s:GridColumn>

            </s:ArrayList>

            </s:columns>

             

            </s:DataGrid>

             

            </s:Application>

            Thanks and Regards,
            ------------------------------------------------------------------------------------------ --
            Vibhuti Gosavi | vgosavi@infocepts.com | www.infocepts.com
            ------------------------------------------------------------------------------------------ -

            • 3. Re: how to restrict a particular column values in a datagrid in flex4 app
              kokorito Level 4

              use the restrict property of the itemrenderer textInput

               

              txt.restrict(0-9);

              will only allow digits between 0 and 9 to be input to the box

               

              txt.restrict(\\-.0-9);

              allows negative and decimal numbers

              • 4. Re: how to restrict a particular column values in a datagrid in flex4 app
                Vibhuti Gosavi(InfoCepts) Level 3

                hi,

                 

                It works :

                 

                <?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]

                public var arr:ArrayCollection=new ArrayCollection([{A1:"aaa" , B1: "bbb"}]);

                 

                ]]>

                </fx:Script>

                <s:DataGrid id="Dg1" x="67" y="97" width="379" editable="true"  dataProvider="{arr}" >

                <s:columns>

                <s:ArrayList>

                <s:GridColumn dataField="A1" headerText="Column 1"></s:GridColumn>

                <s:GridColumn  dataField="B1" headerText="Column 2"></s:GridColumn>

                <s:GridColumn id="col"  headerText="Column 3"  >

                <s:itemRenderer>

                <fx:Component>

                <s:GridItemRenderer>

                <s:TextInput id="txt" restrict="0-9"/>

                </s:GridItemRenderer>

                </fx:Component>

                </s:itemRenderer>

                </s:GridColumn>

                </s:ArrayList>

                </s:columns>

                 

                </s:DataGrid>

                 

                </s:Application>

                Thanks and Regards,
                ------------------------------------------------------------------------------------------
                Vibhuti Gosavi | vgosavi@infocepts.com | www.infocepts.com
                ------------------------------------------------------------------------------------------