2 Replies Latest reply on Nov 30, 2009 10:46 PM by flexbuilder3.0

    Query of Query

    GeorgeWS Level 1

      Im using CF8 and SQL server. I use the Creationcomplete to fire my RO and I get my data into an ArrayCollection. Then I display this array in a DataGrid. All works fine. But I want to get better performance. My issue is I filter the grid with a drop down that also is filled from a RO into an ArrayCollection and the drop down gets filled. So there are 2 calles to very similar data. Im wondering is there a way to take the first call (being all of the data) and the loop over it in AS3 to make the drop down. "Get Distinct Brands" type of thing. OR can I fire off 2 calls to the server and the "Brands" for the drop down come from a Query or Query? Is that even possible.

       

      Thanks

      George

        • 1. Re: Query of Query
          =VA=FyreHeart Level 2

          I do something like that: I pull the data out of the original ArrayCollection, filter and sort it, and then add it to my drop-down menu. My DataGrid is called, imaginatively enough, "MainTable". The "ComboBoxDataProvider" is the custom renderer for the drop-down menu.

           


                      import mx.collections.ArrayCollection;
                      import mx.collections.Sort;
                      import mx.collections.SortField;

           

          //Create the filterable header(s)
                      [Bindable] protected var header:ArrayCollection = new ArrayCollection();
                      private var tempHeader:ArrayCollection;
                      private var tempHeaderText:String;
                     
                      private var tempHeaderField:String;
                      private var tempRow:*;
                      private var tempRowText:String;
                      private var filteredRows:ArrayCollection;
                      private var filterSort:Sort = new Sort();
                     
                      protected function createComboHeaders():void {
                          for(var column:int = 0; column <  MainTable.columns.length; column++) {//Step through each column
                              tempHeader = new ArrayCollection(); //Reinitialize the ArrayCollection for each column
                             
                              //Make the Column Label the first item in the list
                              tempHeaderText = MainTable.columns[column].headerText.toString();
                              tempHeader.addItem(tempHeaderText);
                              tempHeader.addItem({separator:true});
                             
                              //Create an array of items in the column
                              filteredRows = new ArrayCollection;
                              tempRowText='';
                              for(var row:int=0; row<FinancialData.length; row++) {
                                  tempRow = FinancialData[row];
                                  tempHeaderField = MainTable.columns[column].dataField;
                                  if(tempRowText != tempRow[tempHeaderField] && tempRow[tempHeaderField] != '') { //Do a preliminary filter to speed up the next one
                                      filteredRows.addItem(tempRow[tempHeaderField]);
                                      tempRowText = tempRow[tempHeaderField];
                                  }
                              }
                              //Sort and filter the column array
                               filterSort.fields = [new SortField(null, true)];
                              filteredRows.sort = filterSort;
                              filteredRows.refresh();
                              tempRowText='';
                              for(var i:int=0; i<filteredRows.length; i++) {
                                  if(filteredRows[i] != '' && tempRowText != filteredRows[i]) {
                                      tempHeader.addItem(filteredRows[i]);
                                      tempRowText = filteredRows[i];
                                  }
                              }
                              //Add the filter list to the header
                              MainTable.columns[column].comboBoxDataProvider = tempHeader;
                          }
                      }//End createComboHeaders

          • 2. Re: Query of Query
            flexbuilder3.0

            fgsdffrsfs