7 Replies Latest reply on Sep 30, 2014 10:39 PM by Flex harUI

    Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?

    Michelle5002 Level 1
      
      
      
      
      <mx:DataGrid id="animalHistoryDG" left="5" right="5" top="5" bottom="5"
      
      
         
      
      
        editable="true" 
      
      
         
      
      
        dataProvider="{animalHistoryList}" 
      
      
         
      
      
        creationComplete="animalHistoryDG_creationCompleteHandler(event)">
      
      
         
       <mx:columns>
      
      
         
      
       <mx:DataGridColumn id="animalHistoryTypeDC" 
      
      
         
      
      
      
      
      
      
      headerText="Type" 
      
      
         
      
      
      
      
      
      
      editable="true" 
      
      
         
      
      
      
      
      
      
      dataField="historyid"
      
      
         
      
      
      
      
      
      
      labelFunction="lookupAnimalHistoryTypeName"
      
      
         
      
      
      
      
      
      
      editorDataField="selectedItemKey"
      
      
         
      
      
      
      
      
      
      width="300"> 
      
      
         
      
      
       <mx:itemEditor>
      
      
         
      
      
      
       <fx:Component>
      
      
         
      
      
      
      
       <components:GridComboBox 
      
      
         
      
      
      
      
      
       dataProvider="{outerDocument.historyTypesList}" 
      
      
         
      
      
      
      
      
       labelField="name" 
      
      
         
      
      
      
      
      
       lookupField="id" 
      
      
         
      
      
      
      
      
       change="dispatchEvent(new mx.events.DataGridEvent(mx.events.DataGridEvent.ITEM_FOCUS_OUT, true, true))"/>
      
      
         
      
      
      
       </fx:Component>
      
      
         
      
      
       </mx:itemEditor> 
      
      
         
      
       </mx:DataGridColumn>
      
      
      
      
        • 1. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
          Flex harUI Adobe Employee

          I wouldn't say it is "better", but other folks use ModelLocators and Singletons so the custom renderer finds it data in a way that is less tied to the component and its document, and instead tied to the data model for the application.

          • 2. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
            Michelle5002 Level 1

            Do you know of any good examples of this?    And is this what you recommend instead of using outerDocument?

            • 3. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
              Michelle5002 Level 1

              Also, another thing I was thinking of was maybe dispatching an event and even though I do not know bubbling too well yet, but somehow bubble the event up to the parent class and maybe if I was lucky it somehow binds the data that way.   I have started trying to implement this but have not learned enough about bubbling yet to see if it would work.   That was going to be my next attempt when I got back to this topic.

              • 4. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
                Flex harUI Adobe Employee

                If you google ModelLocator and Cairngorm you should see some examples of that.  It's pretty complex.

                 

                If you google ActionScript Singletons you should see some examples and folks arguing about whether it is a good idea or not.

                 

                Basically there is no one right answer.  I would use outerDocument if the data set for the ComboBox needed to be assigned to the enclosing DataGrid.

                 

                And there's nothing wrong with hardcoding if you need to.  A subclass of ComboBox called FiftyUSStatesComboBox should just hard code the 50 states.

                 

                -Alex

                • 5. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
                  Flex harUI Adobe Employee

                  Bubbling is like shouting someone's name in a crowded mall.  If you shout "Michelle" and there is only one person named Michelle within earshot it works great.

                   

                  Bubbling exists mainly because in a complex tree of widgets, your code does not want to have to assign a mouse or keyboard event listener to all widgets.  Then it is a good idea for each widget to shout "mouseOver" since it greatly simplifies your code and your code is usually the only person within earshot.

                  • 6. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
                    Michelle5002 Level 1

                    When I googled your suggestion the first article was putting down the Cairngorm style though he called it a framework.   Now I am wondering what style is taught in Flex in a week?   Also, is there a style you prefer.   I ask because when I ask questions, you are pretty much the only one answering them.   You seem to have your act together.

                    • 7. Re: Combobox in a datagrid column.  Using outerDocument to get data.  Better Way?
                      Flex harUI Adobe Employee

                      I don't know what style is taught in Flex In A Week.  I didn't have to learn Flex the way you do because I was on the team that wrote Flex.

                       

                      There is no one right style.  Each style has trade-offs.  You can build a bird house out of sticks, but you wouldn't use sticks to build a dog house, you would use wood and nails.  But you wouldn't build your own house out of just wood and nails you would use concrete for a foundation and metal connectors for the frame.  And you wouldn't use those to build a skyscraper, you would use steel.  And it also depends on whether you are building one house or twenty.

                       

                      Cairngorm and the model locator was designed to build many skyscrapers quickly (enterprise class applications for the Fortune 500).  It is way too heavy for some lightweight single-purpose mobile app.  You have to decide whether you are building a bird house or a skyscraper or something in-between and get the right building materials.  And don't forget, sometimes the requirements start out as a bird house and later become the largest indoor bird house in the world.  Here's a rough breakdown:

                       

                      -Model Locator:  Heavy, but allows swapping in different data models.  That's useful if you have to write a loan approval app for five different banks.  Each bank will have a slightly different set of customer records and other data fields.  The rest of your code can stay mostly the same as you customize for each bank.  Swappability also helps in "mock" testing.

                      -Singleton: Like Model Locator, allows any code in your app to share the data, but a Singleton doesn't allow swapping.  Not a big deal if you only are writing one loan approval app for one bank.

                      -OuterDocument:  Allows for swapping, but makes it harder to share data with other parts of a large app.

                      -Hard Coding:  No swapping, very easy, but not very flexible.

                       

                      BTW, I only check this forum every few days or so unless I'm engaged in a thread like this.  The reason there are few folks answering questions on this forum is hopefully because everybody is moving to the Apache version of Flex, which where I spend my day.  You'll usually get answers more quickly on the Apache Flex mailing lists.  Questions like yours are best posted by sending an email to users@flex.apache.org.

                       

                      HTH,

                      -Alex