9 Replies Latest reply on Aug 14, 2008 8:34 AM by BrandG

    ItemRenderer halts sorting?

    BrandG
      I've got an ItemRenderer class (descending from DataGridItemRenderer) that has the sum effect of setting the "DataGridListData(super.listData).label" and the "this.text". So, basically just changing the text.

      However, I've noticed that DataGrid rows that employ this ItemRenderer lose the ability to sort. The arrows appear, up and down, they just don't alter the grid at all.

      Does anyone know what causes this, or what I could do to fix it?
        • 1. Re: ItemRenderer halts sorting?
          EDendramis Level 1
          :) I actually had the SAME exact problem. What you're missing is in your itemRenderer you NEED this:

          override public function set data(value:Object):void
          {
          if(value != null)
          {
          super.data = value;

          }
          }

          • 2. Re: ItemRenderer halts sorting?
            BrandG Level 1
            Thanks. I appreciate the quick response. Unfortunately, I was already setting the super.data (should have mentioned that. Sorry).

            I wonder if it's because I'm setting the "super.listData" label, without setting some other value that's used for sorting? I'm searching through the data structure now, just in case.
            • 3. Re: ItemRenderer halts sorting?
              EDendramis Level 1
              I have an item renderer using the attached code. Also, if you are just changing the label, why are you using an itemRenderer? Just use a label function....
              • 4. Re: ItemRenderer halts sorting?
                BrandG Level 1
                Man, with all the work I've done on this ItemRenderer, I'd hate to start over with a label renderer. Originally, I had an itemRenderer like yours in MXML, but I had to move it out to its own class (descending from DataGridItemRenderer) because it didn't shade the text correctly when hovering over it. So now I've got something like this (attached code).

                I was looking into a sortCompareFunction, but that only gives two rows, and no idea which column you're sorting from, which makes a generic solution much more difficult. I would basically have to create a new function for each column of a datagrid, so that it could be sorted by multiple columns. (I see, looking at the support info, that this is a known design bug which is deferred. sigh)

                Guess I'll look at LabelFunctions now.

                Thanks again for your help.



                // Source Follows
                • 5. Re: ItemRenderer halts sorting?
                  EDendramis Level 1
                  labelFunction will suit your purpose much better :)
                  • 6. ItemRenderer halts sorting?
                    BrandG Level 1
                    Gah! Now I'm getting the exact same problem with the labelfunction! How weird is that? Check out this code. It will sort on the first column "Name" but not on the second column "Owner"

                    Okay, so this has nothing to do with the ItemRenderer, because I've taken that out completely. I've stripped this DataGrid down a lot, and I'm still seeing this problem. This has moved beyond annoying, and now it seems kinda cool. :)
                    • 7. Re: ItemRenderer halts sorting?
                      EDendramis Level 1
                      Your label function is odd... what is the format of your data?
                      • 8. Re: ItemRenderer halts sorting?
                        BrandG Level 1
                        The "item" value there points to an object which has, as one of it's members, another object (called "owner"). The owner object has a string in it ("Name") that I'm using as the label.
                        • 9. Re: ItemRenderer halts sorting?
                          BrandG Level 1
                          Okay, I got it. Here's the solution.

                          First, you have to look at the real problem. I was taking an object, with many sub-objects and data values, and I was trying to crowbar that into a datagrid. Because I was having to get intricate details for each object in different fields, I had to create an ItemRenderer (later changed to a LabelFunction) to set the data correctly in the DataGrid.

                          Once that was done, the dynamic data in the DataGrid was making it difficult to sort (how can the dataGrid know what to sort off of when the label is changed dynamically?) This meant that I had to write multiple sort functions (because the sort functions aren't told which column is selected, or even which direction they are sorting). This quickly snowballed into a huge deal.

                          Then it occurred to me: I'm not actually going to change any of this data when it is being displayed (none of the datagrid fields are editable). Why not just take all the data from this uber-complex object, create a new array, put in only the data I want (formatted from the start), and then skip all the labelling, item rendering, sorting hullaballoo?

                          Trying this now, but it seems like a dead simple fix.

                          Thanks again for all your help.