9 Replies Latest reply on Dec 8, 2011 5:56 PM by flexy8

    How to force datagrid headerRenderer to redraw itself?

    flexy8

      Hi guys,

       

          I had datagrid headers that blinks however, I want to turn the blinking off by assigning a new value of a property inside the headerRenderer. The newly assigned value is indeed stored in the property. But my problem is how to force this headerRenderer to redraw itself so it will execute the "override public function prepare(hasBeenRecycled:Boolean)" function as it has the condition that turns the blinking on or off.

       

      Any ideas?

       

      I had this worked but I have to get all the columns object and assign it to an arrayList then set the datagrid's columns to null and apply the arrayList. This works so perfectly in turning on or off the blinking. But this also scrolls up the datagrid back to top which I don't want to happen in my case.

       

      Ideas are much appreciated.

       

      Thanks in advance.

        • 1. Re: How to force datagrid headerRenderer to redraw itself?
          Flex harUI Adobe Employee

          I would move the blink logic to a shared function and have the renderer listen for a change event on some property and run that function.

          • 2. Re: How to force datagrid headerRenderer to redraw itself?
            flexy8 Level 1

            Flex harUI wrote:

             

            I would move the blink logic to a shared function and have the renderer listen for a change event on some property and run that function.

             

            Thanks for the idea. That indeed makes sense! However, how do I assign a new value to some property inside the headerRenderer when PropertyChangeEvent only supports collection classes and ObjectProxy?

             

            example:

            from

            myHeaderRenderer.properties = {blink: true};
            

             

            to

            myHeaderRenderer.properties = {triggerObject.blink: true} // or triggerObject['blink']: true doesn't work either.
            

             

            Unless there is a way for the headerRenderer to listen to a property change outside of itself (referencing to the parent objects)

            OR

            a way to call a function inside the headerRenderer from the main (parent) document.

             

             

            Thanks in advance for your reply Flex harUl.

            • 3. Re: How to force datagrid headerRenderer to redraw itself?
              Flex harUI Adobe Employee

              What is changing that makes you want to change the renderer?  Whatever it is can dispatch an event, and you can have the renderer listen for it.

              • 4. Re: How to force datagrid headerRenderer to redraw itself?
                flexy8 Level 1

                Ok so, if there is a negative number that is displayed in the datagrid, the headerRenderer should blink so the user will detect that there is a negative value inside the datagrid. I tried dispatching a custom event but I'm not quite sure if I did the right code in the headerRenderer to listen to it since it doesn't fire off the function on the listener.

                 

                Do I have to somehow access a parent document and have the listener listened to it? How? parent.addEventListener?...

                 

                I assumed that the dispatching of the custom event should have the bubble property set to true so the headerRenderer can listen to it. Just correct me if my understanding on this isn't right.

                 

                Thanks,

                • 5. Re: How to force datagrid headerRenderer to redraw itself?
                  Flex harUI Adobe Employee

                  The headerRenderer’s owner property should be the DataGrid.  Bubble is not necessary as you are listening to the dispatching object.

                  1 person found this helpful
                  • 6. Re: How to force datagrid headerRenderer to redraw itself?
                    flexy8 Level 1

                    Thanks. It does now fires the function of the listener if and only if the event is dispatched by the datagrid/column.

                     

                    e.g.,

                    dataGrid.dispatchEvent() ..  or dataGridColumnID.dispatchEvent() ..

                     

                    However, when I hover over the dataGrid headers, it fires off that listener function. And also, even though the property inside the headerRenderer was changed from the main document, and the listener function was fired, the property wasn't changed from the headerRenderer's perspective.. It only updates when switching states in the main document --  for it redraws the datagrid.

                     

                    So here's my idea but doesn't know how to achieve it:

                    1. Dispatch a custom event to the framework not to an object (datagrid or column) - so it won't call the listener function everytime the mouse hovered the headers.
                    2. Have the listener from the headerRenderer listen to it.
                    3. OR, in the headerRenderer's listener function, access the data from the main or parent document -- as the changed data is updated in contrast with the property inside the headerRenderer that wasn't updated even if the value is already changed.
                    4. OR, I know this isn't possible, access a function inside the headerRenderer from the main to run it.
                    • 7. Re: How to force datagrid headerRenderer to redraw itself?
                      flexy8 Level 1

                      I had it working now.. I apologize for being a little lazy earlier. In accessing the data of the outer document from inside the headerRenderer, using the owner property, drilling down to the headerRenderer's properties property of the column of the datagrid does this trick. It now turns the blinking on/off very nicely.

                       

                      What's not nice here is the listener function is called everytime a mouse is hovered over the headers -- an idea to solve this is much appreciated.

                       

                      Thanks once again,

                      • 8. Re: How to force datagrid headerRenderer to redraw itself?
                        Flex harUI Adobe Employee

                        Post some code.  It sounds like it still isn’t set up correctly.

                         

                        When do you determine that there is a negative value?  On a collectionChange event?  If that logic sets a flag you add to the subclass of a datagrid and setting that flag dispatches an event and the renderer is only listening for that event, I would think that should be sufficient.

                        • 9. Re: How to force datagrid headerRenderer to redraw itself?
                          flexy8 Level 1

                          Yeah my bad, it wasn't set up correctly. But it was fixed just now.

                           

                          The reason why it keeps on executing the listener's function everytime the mouse hovered the datagrid headers is I placed a function call (of the listener's function) right inside the "prepare()" function of the headerRenderer. Well, my reason for doing this earlier is it should execute the function that causes the headers to blink (or not) everytime the datagrid shows up -- meaning, it should run the code for this time only aside when some data changes to have this function execute again.

                           

                          The fix was a listener was set up on the headerRenderer's initialize event and then dispatch the custom event that its listening to at creation complete. So this suffice the execution of the function at first time. Then when some data changes from the main occurs, it dispatches an event that the headerRenderer is listening and, poof!

                           

                          Thanks so much for the help Flex harUl