13 Replies Latest reply on Jan 23, 2009 10:01 AM by Newsgroup_User

    DataGrid Headers

    tegs1979
      Hey guys,

      Does anyone have any idea how to get hold of a specific column header renderer in a datagrid?

      My app checks the contents of a datagrid and highlights any incorrect columns/rows in red. Easy enough for the cells themselves: I can get at the listItems in the grid, iterate through them and mess with their itemRenderer's opaqueBackground value.

      Question is: how on earth do I do the same for the header renderers? There seems to be no way to "get at them" in order to change their properties.

      I've seen people create a new ClassFactory and apply it to specific datagrid columns, but that feels messy - I just want to get hold of the ones that are already there.

      Any help would be much appreciated!

      Thanks,

      Tegs
        • 1. Re: DataGrid Headers
          ntsiii Level 3
          Perhaps through the DG.columns array? That will let you access the individual DataGridColumn instances. Perhaps there is a headerRenderer propety you can access?
          • 2. Re: DataGrid Headers
            tegs1979 Level 1
            Thanks for the reply Tracy!

            Yeah, I'm already getting at the DataGridColumns for the grid, but that's the problem - I can't then get then headerRenderer for it. The property headerRenderer returns the Class Factory (which I can replace) but not the actual renderers themselves.

            They must be held somewhere, surely???

            The search continues...

            tegs
            • 3. Re: DataGrid Headers
              ntsiii Level 3
              google this if you have not already...
              • 4. Re: DataGrid Headers
                Level 7

                "tegs1979" <webforumsuser@macromedia.com> wrote in message
                news:gl52u7$sf6$1@forums.macromedia.com...
                > Hey guys,
                >
                > Does anyone have any idea how to get hold of a specific column header
                > renderer
                > in a datagrid?
                >
                > My app checks the contents of a datagrid and highlights any incorrect
                > columns/rows in red. Easy enough for the cells themselves: I can get at
                > the
                > listItems in the grid, iterate through them and mess with their
                > itemRenderer's
                > opaqueBackground value.

                You should never be putting your fingers into renderers from the outside
                like this. Instead, you might find something like this useful:
                http://flexdiary.blogspot.com/2008/09/extended-datagrid-with-stylefunction.html

                I know that the styleFunction gets called on the header renderers, but I'm
                not sure what data gets passed in.

                HTH;

                Amy


                • 5. Re: DataGrid Headers
                  tegs1979 Level 1
                  Googled for days and found nothing. Dug through the docs and found nothing. Messed on for hours and found nothing.

                  The truth is out there, but I'm damned if I can find it.

                  tegs
                  • 6. Re: DataGrid Headers
                    rtalton Level 4
                    Hmmm. I checked into this yesterday and found nothing, really.
                    What do you want the header renderer to do, change appearance when there is an error somewhere in the data grid or something?
                    If you define it that way, I'm sure someone will have the solution for you.
                    • 7. Re: DataGrid Headers
                      tegs1979 Level 1
                      Cheers rtalton/Amy,

                      Well, I've got a 10x10 datagrid that allows people to put their own text into its cells. They can then click a "Check" button that whizzes through the data provider and checks for errors. If any are found, I find the corresponding itemRenderer and set its opaqueBackground to red. This works really well (even if it is a little inelegant).

                      Problem is, I'd also like to highlight the column header too - but that's not so easy. I need to do it from "outside" the renderer too as that's where the error checking is happening.

                      @Amy - this method seemed like the most logical way to solve the problem - I'm surprised Flex doesn't support it. What kind of issues can I expect messing with the Class Factory like this?

                      Thanks again for the help guys - much appreciated!
                      • 8. Re: DataGrid Headers
                        Level 7

                        "tegs1979" <webforumsuser@macromedia.com> wrote in message
                        news:gl85ne$p97$1@forums.macromedia.com...
                        > Cheers rtalton/Amy,
                        >
                        > Well, I've got a 10x10 datagrid that allows people to put their own text
                        > into
                        > its cells. They can then click a "Check" button that whizzes through the
                        > data
                        > provider and checks for errors. If any are found, I find the corresponding
                        > itemRenderer and set its opaqueBackground to red. This works really well
                        > (even
                        > if it is a little inelegant).
                        >
                        > Problem is, I'd also like to highlight the column header too - but that's
                        > not
                        > so easy. I need to do it from "outside" the renderer too as that's where
                        > the
                        > error checking is happening.

                        A styleFunction _does_ operate from outside the renderer.

                        > @Amy - this method seemed like the most logical way to solve the problem -
                        > I'm
                        > surprised Flex doesn't support it. What kind of issues can I expect
                        > messing
                        > with the Class Factory like this?

                        For one thing, I'd expect that once you have enough data to need scrolling,
                        the whole thing will go to heck. But in a more general sense, it's just
                        plain bad practice. The whole idea behind components is that you drop them
                        into your file and they are responsible for themselves. The component
                        developer exposes properties and methods that allow you to do as much
                        customization as the component is built to handle.

                        I don't understand why the Flex team did not implement styleFunction for
                        DataGrid, since the code already existed in AdvancedDataGrid, and it only
                        took me about 6 hours to track down where to put the logic to make it work
                        with DG. I suspect that for someone more intimately familiar with the code,
                        it would have been an effort of less than an hour. With a styleFunction in
                        place, you can do a _lot_ more without having to have so much custom code in
                        your renderer.

                        The big issue for you with using styleFunction is how to determine from the
                        header if any item in the column has an error. I think that will involve
                        using an IViewCursor to seek any item meeting the error condition for that
                        property in the collection, and if one is found returning a style object
                        with the changed style.

                        Hope this clarifies.

                        -Amy


                        • 9. Re: DataGrid Headers
                          tegs1979 Level 1
                          Hi Amy,

                          Thanks for clarifying all that - I had a feeling I was doing this wrong somehow (hence the obvious inability to get at the renderers). My biggest problem really is that the renderer has no way of knowing if the text it contains is wrong - the check is quite complex and is based on the content and positions of all the other cells in the grid.

                          I wonder then: is there any way to set up the data provider to hold a boolean property for each item - e.g. showAsError or something? That way I can check the dataProvider and make changes to that - the renderers will then pick up on it and react accordingly? That sounds a little cleaner?

                          Cheers,

                          tegs
                          • 10. Re: DataGrid Headers
                            Level 7

                            "tegs1979" <webforumsuser@macromedia.com> wrote in message
                            news:gl9b1k$7um$1@forums.macromedia.com...
                            > Hi Amy,
                            >
                            > Thanks for clarifying all that - I had a feeling I was doing this wrong
                            > somehow (hence the obvious inability to get at the renderers). My biggest
                            > problem really is that the renderer has no way of knowing if the text it
                            > contains is wrong - the check is quite complex and is based on the content
                            > and
                            > positions of all the other cells in the grid.

                            Have you even _looked_ at using the extended DataGrid with the
                            styleFunction???

                            The renderer doesn't _need_ to know about the error. The styleFunction can
                            figure it out, and the styleFunction "lives" at the same level as the
                            dataGrid.

                            Just so's you know, I tend to get a little pissy if I am trying to help
                            someone and it seems that they haven't at least looked into trying the
                            option that I've given them that I think will be most helpful. If they
                            ignore my major advice long enough, if they're lucky I'll yell at them and
                            keep helping them. If they're not lucky, I just quit replying to their
                            questions.

                            > I wonder then: is there any way to set up the data provider to hold a
                            > boolean
                            > property for each item - e.g. showAsError or something? That way I can
                            > check
                            > the dataProvider and make changes to that - the renderers will then pick
                            > up on
                            > it and react accordingly? That sounds a little cleaner?

                            If your dataProvider is a collection of dynamic objects, you can just add
                            the property on as you check. If not, you'll need to add it to the class
                            definition.

                            HTH;

                            Amy


                            • 11. Re: DataGrid Headers
                              tegs1979 Level 1
                              Eek - sorry. I didn't mean to be an annoyance (I seem to be having that effect on people today). I do appreciate you taking the time to help out...

                              I'm starting to get my head around the way flex works now, and can see why my (sought) approach is wrong and yours is right. Bear in mind that this time last week I'd never even heard of flex :)

                              Thanks again,

                              tegs
                              • 12. Re: DataGrid Headers
                                rtalton Level 4
                                Hey tegs, you're doing great! It took me at least a week in here before Amy took the whip to me. Seriously, Amy's the bomb. The Flex bomb.
                                She has a very informative FAQ here:
                                http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
                                ..with lots of great info on item renderers. This Forum should have a permalink to it.

                                Hope you stick around. Don't get frustrated with the software; it will eventually all make sense to you as you absorb the info here. And the whippings.
                                • 13. Re: DataGrid Headers
                                  Level 7

                                  "rtalton" <webforumsuser@macromedia.com> wrote in message
                                  news:glcoon$hsq$1@forums.macromedia.com...
                                  > Hey tegs, you're doing great! It took me at least a week in here before
                                  > Amy
                                  > took the whip to me. Seriously, Amy's the bomb. The Flex bomb.
                                  > She has a very informative FAQ here:
                                  > http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf
                                  > ..with lots of great info on item renderers. This Forum should have a
                                  > permalink to it.

                                  My experience is that I learn better when I'm slightly annoyed. So I try to
                                  spread the wealth ;-)