Filtering an Aggregated DataGrid From the List Box

Reference:

This topic provides sample code for filtering an aggregated DataGrid. It also describes the functions that accomplish this task.


Top of page

Example: Sample Code for Filtering an Aggregated DataGrid
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="initApp()" viewSourceURL="doc_api4_filter_reset/index.html">
  <mx:Script>
    <![CDATA[
      private var grid1:ibiObject = new ibiObject();
      private var fex:String = "http://localhost:8080/ibi_apps/WFServlet
         ?IBIF_ex=xmltest";
      private var a:Array = ['[ALL]'];
      private var aggField:Array = ['DOLLARS'];
      private var byField:Array = ['REGION','CITY'];
      private var calOpts:Array = ['Sum','Average'];
      private var columnArray:Array = new Array();
      private var filterOption:Array = ['EQ'];
      private var selectedItem:Array = new Array();
      private function grid1_agg(useFilter:Boolean=true):void
      {
        grid1.aggregate(aggField, byField,calOpts, useFilter, false);
        main1agg.dataProvider = grid1.prGridagg;
      }
      private function initApp():void
      {
        System.useCodePage=true;
        grid1.init(fex,dataReady);
      }
      private function dataReady(grid:ibiObject,obj:*):void
      {
        grid1.populateGrid(false);
        grid1_agg();
        loadLists(true,true);
      }
      private function loadLists(city:Boolean,region:Boolean):void
      {
        if(city)cityList.dataProvider =
            a.concat(grid1.getUniqueValues("CITY",true));
        if(region)regionList.dataProvider =
            a.concat(grid1.getUniqueValues("REGION",true));
      }
      private function updateList(list:Object,col:String):void
      {
        if(list.selectedItem.toString() != '[ALL]'){
          columnArray = [col];
          selectedItem = [[list.selectedItem.toString()]];
          grid1.filter(columnArray, filterOption, selectedItem, null , false);
          grid1_agg();
          if(col=='REGION')loadLists(true,false);
        }
        else{
          grid1_agg(false);
        }
      }
    ]]>
  </mx:Script>
  <mx:List x="10" y="199" id="regionList" change="updateList(regionList,'REGION')"
      height="101" width="129"></mx:List> 
  <mx:List x="156" y="199" id="cityList" change="updateList(cityList,'CITY')"
      height="101" width="135"></mx:List>
  <mx:DataGrid x="10" y="38" width="477" id="main1agg" height="153">
    <mx:columns>
      <mx:DataGridColumn id="col1" headerText="Region" dataField="REGION"/>
      <mx:DataGridColumn id="col2" headerText="City" dataField="CITY"/>
      <mx:DataGridColumn id="col3" headerText="Total Sales"
          dataField="Sum.DOLLARS"/>
      <mx:DataGridColumn id="col4" headerText="Average Sales"
          dataField="Average.DOLLARS"/>
    </mx:columns>
  </mx:DataGrid> 
</mx:Application>



x
Reference: Functions for Filtering an Aggregated DataGrid
public function addSelectedColumn(addLabel:String):void

Description:
Adds a column from the existing DataGrid. If a column name is present in the DataGrid, it does not add any column in the DataGrid.

Parameters:
addLabel of type String: Takes a column name of string type.

public function calculate(calculateColumnName:String,calculateOption:String):void

Description:
Calculates the sum, minimum, maximum, and average values of a column. This function does not return a value. It just adds an extra row to the DataGrid showing the result of the specified operation. The calculateColumnName parameter specifies which column is used for the specified operation. The calculateOption parameter specifies which operation is performed: min, max, sum, average, count, distinct.

Parameters:
calculateColumnName of type String: Specifies which column is used to do the calculation.

calculateOption of type String: Specifies which operation to perform on the column specified by calculateColumnName.

public function copyCollection(copyCollection:ArrayCollection):ArrayCollection

Description:
Copies a collection to another collection. Returns a collection.

Parameters:
copyCollection of type ArrayCollection: Takes a collection name.

public function getCalculateRowVisible():Boolean

Description:
Checks to see if a row has been added to the grid to show the result of a calculate() call. If it has been added, then a new call to calculate() does not add an extra row.

public function getColumnIndex(columnName:String):int

Description:
Gets the index number of the column specified in columnName. If not found, this function returns -1.

Parameters:
columnName of type String: Takes a column name of string type.

public function GroupBy(byLabel:Array):ArrayCollection

Description:
Returns an ArrayCollection of by fields.

Parameters:
byLabel of type Array: Takes an array of items.

public function loadWorkingRows():void

Description:
Loads all the indexes of all the rows of the grid into the array WorkRows to be used by the filter function.

public function removeSelectedColumn(removeLabel:String):void

Description:
Removes a column from the existing DataGrid. If a column name is present in the DataGrid, it will remove it from there.

Parameters:
removeLabel of type String: Takes a column name of string type.

public function uniqueValuesFunction(rowItems:Array):Array

Description:
Gets a unique value from the rowItems of the DataGrid.

Parameters:
rowItems of type Array: Passes all rowItems from each field of the DataGrid.


WebFOCUS