0

My datagrid has 3 columns and the third column is having the textinput itemEditor. when the text changes and if that text matches with any other text(basically the text is an int). the popUp should appear as duplicate. here is the code what i wrote which actually not working properly and I'm new to the flex, so please don't mind if my code is weird.

<s:GridItemEditor 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[
            import mx.controls.Alert;

            override public function set data(value:Object):void
            {
                super.data = value;
                col3TextField.text = data.columnThree;
            }
            /*
            override public function set value(newValue:Object):void {
                col3TextField.text = newValue as String;
            }
            */

            override public function get value():Object {
                if (parseInt(col3TextField.text) == data.columnThree) {
                    return data[column.dataField];
                } 
                return  col3TextField.text;
            }

            override public function save():Boolean
            {
                if (parseInt(col3TextField.text) == data.columnThree) {



    Alert.show("Duplicate");
                    }
                }  
                data[column.dataField] = value;
                return  true;
            }       


        ]]>
    </fx:Script>
    <s:TextInput id="col3TextField" width="100%" color="red" restrict="0-9" maxChars="4"/>
</s:GridItemEditor>

<s:DataGrid x="139" y="340" width="300" height="300" dataProvider="{dgData}" editable="true" 
                >
        <s:columns>
            <s:ArrayList>
                <s:GridColumn dataField="columnOne" headerText="Data Col #1"  editable="false"/>
                <s:GridColumn dataField="columnTwo" headerText="Data Col #2" editable="false"/>
                <s:GridColumn dataField="columnThree" headerText="Data Col #3" itemEditor="custom.CustomItemEditor" >
                </s:GridColumn>
            </s:ArrayList>
        </s:columns>
    </s:DataGrid>
ketan
  • 19,129
  • 42
  • 60
  • 98
dam
  • 33
  • 11
  • This question is very confusing; I'm not sure where to start. "When the text changes" What text are you referring to? The text in the itemEditor? What popup are you referring to? What does the popup have to do with duplicates? What is duplicated? As far as I can tell the save function of the itemEditor is never called. Are you sure that parseInt(col3TextField.text) is returning a value? – JeffryHouser May 16 '13 at 12:01

1 Answers1

0

Instead of dispatching the alert from inside the ItemRenderer, dispatch a custom event with an ID like "ItemSaveEvent" and handle your business logic either where the datagrid lives, or even better, in a presentation model.

That said, be careful with your equality check. parseInt returns a Number type. Is your data.columnthree a Number? If so, then make sure you want value equality:

See this stackOverflow post that hints on custom events in itemRenderers.

Community
  • 1
  • 1
TomSchober
  • 433
  • 4
  • 12