9 Replies Latest reply on Dec 1, 2008 1:43 PM by rtalton

    Datagrid labelfunction timing

    tberg3db
      I have a dataGrid that uses a labelFunction for one of the columns to display a text string instead of the foreign key integer. Most times the column text does not display when the dataGrid is initially displayed, but will always display after I update dataGrid's dataProvider. So I must have a timing problem. The dataProvider for the dataGrid is an ArrayCollection that is populated through an AMF remote object. This occurs initially using the Application's 'creationComplete' event. I appreciate any ideas to help me solve this issue.
      Thanks,
      Todd
        • 1. Re: Datagrid labelfunction timing
          rtalton Level 4
          Does the foreign key integer always display if you disable the labelFunction, or do you still get nothing?
          • 2. Re: Datagrid labelfunction timing
            tberg3db Level 1
            Yes, if I remove the labelFunction the integer is always displayed correctly.
            • 3. Re: Datagrid labelfunction timing
              Level 7

              "tberg3db" <webforumsuser@macromedia.com> wrote in message
              news:gghem1$qes$1@forums.macromedia.com...
              >I have a dataGrid that uses a labelFunction for one of the columns to
              >display a
              > text string instead of the foreign key integer. Most times the column
              > text
              > does not display when the dataGrid is initially displayed, but will always
              > display after I update dataGrid's dataProvider. So I must have a timing
              > problem. The dataProvider for the dataGrid is an ArrayCollection that is
              > populated through an AMF remote object. This occurs initially using the
              > Application's 'creationComplete' event. I appreciate any ideas to help
              > me
              > solve this issue.

              Are you getting a collection change event on the ArrayCollection?


              • 4. Re: Datagrid labelfunction timing
                tberg3db Level 1
                Sorry, I didn't give much info. I've included relevant code now. When I put a breakpoint in the labelFunction, the cAccountsDP ArrayCollection is empty at the time the page is displayed. I have another function that updates the dataGrid selectedItem values with formItem inputs. When that function is run, the labelFunction gets fired again and now the cAccountsDP ArrayCollection is populated and the column is displayed correctly.
                • 5. Re: Datagrid labelfunction timing
                  Level 7

                  "tberg3db" <webforumsuser@macromedia.com> wrote in message
                  news:gghq1v$b8e$1@forums.macromedia.com...
                  > Sorry, I didn't give much info. I've included relevant code now. When I
                  > put a
                  > breakpoint in the labelFunction, the cAccountsDP ArrayCollection is empty
                  > at
                  > the time the page is displayed. I have another function that updates the
                  > dataGrid selectedItem values with formItem inputs. When that function is
                  > run,
                  > the labelFunction gets fired again and now the cAccountsDP ArrayCollection
                  > is
                  > populated and the column is displayed correctly.
                  >
                  > <mx:Script>
                  > <![CDATA[
                  > [Bindable]
                  > public var cAccountsDP:ArrayCollection;
                  > [Bindable]
                  > public var contactsDP:ArrayCollection;
                  >
                  > // Application 'creationComplete' function
                  > protected function ContactsInit():void
                  > {
                  > cAccountsDP = ActiveRecords.Accounts.findAll( );
                  > contactsDP = ActiveRecords.Contacts.findAll( );
                  > }

                  before your closing bracket just above, put this:

                  cAccountsDP.addEventListener(CollectionEvent.COLLECTION_CHANGE,
                  changeHandler);
                  contactsDP..addEventListener(CollectionEvent.COLLECTION_CHANGE,
                  changeHandler);

                  then add this somewhere in your code

                  private function changeHandler(e:CollectionEvent):void {
                  //put break point here
                  }

                  Does the event fire for either collection?

                  Hope this clarifies;

                  Amy


                  • 6. Re: Datagrid labelfunction timing
                    tberg3db Level 1
                    Stepping through the breakpoints, the event fires first for the contactsDP, then for the labelFunction, then for the cAccountsDP.
                    • 7. Re: Datagrid labelfunction timing
                      Level 7

                      "tberg3db" <webforumsuser@macromedia.com> wrote in message
                      news:gghtov$fq0$1@forums.macromedia.com...
                      > Stepping through the breakpoints, the event fires first for the
                      > contactsDP, then for the labelFunction, then for the cAccountsDP.

                      Try setting the dp in the collection change handler instead of setting it
                      before the collection has arrived, using a temp var if necessary.

                      HTH;

                      Amy


                      • 8. Re: Datagrid labelfunction timing
                        tberg3db Level 1
                        The solution I found was to use the dataGrid's preinitialize event to set the dataProvider for the column labels.
                        Todd
                        • 9. Re: Datagrid labelfunction timing
                          rtalton Level 4
                          You don't mention if you did this, but might also check into using a result handler on the remote object to assign the dataprovider to the Data Grid.