5 Replies Latest reply on Aug 7, 2011 3:11 AM by Francisc

    Regarding dataProvider for Non-List based component

    Mani S

      Hi,

       

      I have requirement for providing dataprovider property for my custom panel component as like list based components. My custom component is derived from native Panel component (for some requirement iderived it from Panel component).

       

      How to implement the dataProvider property for Non-List based components and is it possible?

       

       

      Regards,

      Manikandan.S

        • 1. Re: Regarding dataProvider for Non-List based component
          kokorito Level 4

          just make a public variable in the component

          • 2. Re: Regarding dataProvider for Non-List based component
            Francisc Level 3

            Kokorito's correct.

             

            I'll just expand on that a bit, but it's his answer if you consider this to be what you need.

             

            In your custom component make a public property and name it what you want, probably dataProvider for consistency like this:

             

            public var dataProvider:WhatYouWant;

             

            "WhatYouWant" can be of the type you require. Make it an ArrayCollection if you want to be able to listen to the collectionChange event and perform an action when it's assigned or whenever it changes.

             

            You can also create a public function to which you pass variable or variables that performs a function.

             

            Lot's of ways to do this.

            • 3. Re: Regarding dataProvider for Non-List based component
              Mani S Level 1

              Ya i have made that. But it's not updating in the view. How to set the values to the custom panel component?

              • 4. Re: Regarding dataProvider for Non-List based component
                Mani S Level 1

                Actually i have provided property like following:

                 

                        public function get listDataProvider():IList
                        {      
                            return dataGroup.dataProvider;
                        }
                       
                        public function set listDataProvider(value:IList):void
                        {
                             dataGroup.dataProvider = value;
                             dispatchEvent(new Event("dataProviderChanged"));
                        }

                 

                But the values are not shown in the component while executinng.

                 

                For reference here am showing the image,

                 

                Am setting the same arrayCollection value to both native list and my custom panel component. But result is not shown in my custom panel component.

                 

                What i have to do to show the collection value in my custom panel component (derived from panel)?

                 

                PanellDataProvider.JPG

                • 5. Re: Regarding dataProvider for Non-List based component
                  Francisc Level 3

                  There's a "native" way of doing that in Flex:

                   

                  Try something along the lines of

                   

                  myArrayCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE,onDataChange);

                   

                  ...

                   

                  protected function onDataChange(event:CollectionEvent):void

                  {

                       //Do stuff, refresh etc

                  }

                   

                  Also, make the variable [Bindable] when you declare it.