4 Replies Latest reply on Mar 17, 2008 7:01 AM by peterent

    Finding data in a datagrid

    SiHoop Level 1
      I've just added data to a datagrid and sorted the new column. Now I want to locate the new data in the datagrid. How can I find the index of a piece of data in the datagrid?
      Thanks!
        • 1. Re: Finding data in a datagrid
          peterent Level 2
          Your data is stored in a Collection - that's what's been sorted. Using the Collection's getItemAt(index) will work that sort.
          • 2. Re: Finding data in a datagrid
            SiHoop Level 1
            My collection is named classesColumn, so I tried: trace("test="+classesColumn.getItemAt(2))
            and the result was:
            test=[object Object].
            What I really want to do is to retrieve the index of a specific entry in the collection. How can I do that?
            • 3. Re: Finding data in a datagrid
              SiHoop Level 1
              OK, I've discovered getItemIndex, but I still have a problem. I think that my issue may be that I am returning several variables in my collection as opposed to having a simple array that I can point to. If this is the case, how would I access just one of the variables stored in the collection, and how would I retrieve a specific index of that variable?
              Thanks again!
              • 4. Re: Finding data in a datagrid
                peterent Level 2
                Let's assume you have a collection from this array:
                var a:Array = [ {make:"Toyota",model:"MR2",year:1985,price:2000}, {make:"Ford",model:"Fusion",year:2005,price:13000}, etc. ];

                and turned into an ArrayCollection:
                var col:ArrayCollection = new ArrayCollection( a );

                When sorted, getItemIndex(2) will return one of the objects that has make, model, year, and price fields. I *think* that's what you mean by 'variable' in your case. So:

                var item:Object = col.getItemAt(2);
                trace("Make",item.make,"Model",item.model,"Year",item.year,"Price",item.price);

                should get you want you are looking for.