0 Replies Latest reply on Jul 6, 2011 1:42 AM by Falex7

    OLAPDatagrid wordwrap and variable row height

    Falex7

      Hi,

       

         Does anyone have an idea how to get wordwrap and  variablerowheight work for OLAPDataGrid, Here is the example which I am  trying but it is not working.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="creationCompleteHandler()">
      <mx:Script>
          <![CDATA[
      import mx.rpc.AsyncResponder;
              import mx.rpc.AsyncToken;
              import mx.olap.OLAPQuery;
              import mx.olap.OLAPSet;
              import mx.olap.IOLAPQuery;
              import mx.olap.IOLAPQueryAxis;
              import mx.olap.IOLAPCube;
              import mx.olap.OLAPResult;
              import mx.events.CubeEvent;
              import mx.controls.Alert;
              import mx.collections.ArrayCollection;
             
             
              //
              // Format of Objects in the ArrayCollection:
              //
              //  data:Object = {
              //    customer:"AAA",
              //    product:"ColdFusion",
              //    quarter:"Q1"
              //    revenue: "100.00"
              //  }
              //

       

              [Bindable]
              private var flatData:ArrayCollection = new ArrayCollection(
              [
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"ColdFusion", quarter:"Q1", revenue:210, cost:25},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flex", quarter:"Q2", revenue:210, cost:25},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Dreamweaver", quarter:"Q3", revenue:250, cost:125},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flash", quarter:"Q4", revenue:430, cost:75},

       

               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"ColdFusion", quarter:"Q2", revenue:125, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flex", quarter:"Q3", revenue:210, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Dreamweaver", quarter:"Q4", revenue:320, cost:120},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flash", quarter:"Q1", revenue:280, cost:70},

       

               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"ColdFusion", quarter:"Q3", revenue:375, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flex", quarter:"Q4", revenue:430, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Dreamweaver", quarter:"Q1", revenue:470, cost:220},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flash", quarter:"Q2", revenue:570, cost:170},
         
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"ColdFusion", quarter:"Q4", revenue:215, cost:90},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flex", quarter:"Q1", revenue:210, cost:90},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Dreamweaver", quarter:"Q2", revenue:175, cost:190},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flash", quarter:"Q3", revenue:670, cost:75},
         
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"ColdFusion", quarter:"Q1", revenue:175, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flex", quarter:"Q2", revenue:210, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Dreamweaver",quarter:"Q3", revenue:120, cost:120},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flash", quarter:"Q4", revenue:310, cost:70},
         
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"ColdFusion", quarter:"Q1", revenue:385, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flex", quarter:"Q2", revenue:340, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Dreamweaver", quarter:"Q3", revenue:470, cost:220},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flash", quarter:"Q4", revenue:270, cost:170},
         
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"ColdFusion", quarter:"Q1", revenue:100, cost:25},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flex", quarter:"Q2", revenue:150, cost:25},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Dreamweaver", quarter:"Q3", revenue:200, cost:125},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flash", quarter:"Q4", revenue:300, cost:75},
         
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"ColdFusion", quarter:"Q2", revenue:175, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flex", quarter:"Q3", revenue:100, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Dreamweaver", quarter:"Q4", revenue:270, cost:120},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flash", quarter:"Q1", revenue:370, cost:70},
         
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"ColdFusion", quarter:"Q3", revenue:410, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flex", quarter:"Q4", revenue:300, cost:320},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Dreamweaver", quarter:"Q1", revenue:510, cost:220},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flash", quarter:"Q2", revenue:620, cost:170},
         
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"ColdFusion", quarter:"Q4", revenue:215, cost:90},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flex", quarter:"Q1", revenue:210, cost:90},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Dreamweaver", quarter:"Q2", revenue:175, cost:190},
               {customer:"AAA AAA AAA AAA AA AAAAA AAAA AA", product:"Flash", quarter:"Q3", revenue:420, cost:75},
         
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"ColdFusion", quarter:"Q1", revenue:240, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flex", quarter:"Q2", revenue:100, cost:20},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Dreamweaver", quarter:"Q3", revenue:270, cost:120},
               {customer:"BBB BB BBBBB BBB BBB BBB BBB BBB BBB BBBB", product:"Flash", quarter:"Q4", revenue:370, cost:70},
         
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"ColdFusion", quarter:"Q1", revenue:375, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flex", quarter:"Q2", revenue:420, cost:120},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Dreamweaver", quarter:"Q3", revenue:680, cost:220},
               {customer:"CCC CCC CCCCC CCCC CCCCCCCCC CCC CCC", product:"Flash", quarter:"Q4", revenue:570, cost:170}        
              ]);
         
              private function creationCompleteHandler():void {
                  // You must initialize the cube before you
                  // can execute a query on it.
                  myMXMLCube.refresh();
              }

       

              // Create the OLAP query.
              private function getQuery(cube:IOLAPCube):IOLAPQuery {
                  // Create an instance of OLAPQuery to represent the query.
                  var query:OLAPQuery = new OLAPQuery;
                 
                  // Get the row axis from the query instance.
                  var rowQueryAxis:IOLAPQueryAxis =
                      query.getAxis(OLAPQuery.ROW_AXIS);
                  // Create an OLAPSet instance to configure the axis.
      //            var productSet:OLAPSet = new OLAPSet;
      //            // Add the Product to the row to aggregate data
      //            // by the Product dimension.
      //            productSet.addElements(
      //                cube.findDimension("ProductDim").findAttribute("Product").children);
      //            // Add the OLAPSet instance to the axis.
      //            rowQueryAxis.addSet(productSet);
                 
                  var productSet:OLAPSet = new OLAPSet;
                  // Add the Product to the row to aggregate data
                  // by the Product dimension.
                  productSet.addElements(
                      cube.findDimension("CustomerDim").findAttribute("Customer").children);
                  // Add the OLAPSet instance to the axis.
                  rowQueryAxis.addSet(productSet);
                 
                  // Get the column axis from the query instance, and configure it
                  // to aggregate the columns by the Quarter dimension.
                  var colQueryAxis:IOLAPQueryAxis =
                      query.getAxis(OLAPQuery.COLUMN_AXIS);        
                  var quarterSet:OLAPSet= new OLAPSet;
                  quarterSet.addElements(
                      cube.findDimension("QuarterDim").findAttribute("Quarter").children);
                  colQueryAxis.addSet(quarterSet);
                 
                  return query;      
              }

       

              // Event handler to execute the OLAP query
              // after the cube completes initialization.
              private function runQuery(event:CubeEvent):void {
                  // Get cube.
                  var cube:IOLAPCube = IOLAPCube(event.currentTarget);
                  // Create a query instance.
                  var query:IOLAPQuery = getQuery(cube);
                  // Execute the query.
                  var token:AsyncToken = cube.execute(query);
                  // Setup handlers for the query results.
                  token.addResponder(new AsyncResponder(showResult, showFault));
              }

       

              // Handle a query fault.
              private function showFault(result:Object, token:Object):void {
                  Alert.show("Error in query.");
              }

       

              // Handle a successful query by passing the query results to
              // the OLAPDataGrid control..
              private function showResult(result:Object, token:Object):void {
                  if (!result) {
                      Alert.show("No results from query.");
                      return;
                  }
                  myOLAPDG.dataProvider= result as OLAPResult;           
              }               
          ]]>
      </mx:Script>
      <mx:OLAPCube name="FlatSchemaCube"
          dataProvider="{flatData}"
          id="myMXMLCube"
          complete="runQuery(event);">
          
          <mx:OLAPDimension name="CustomerDim">
              <mx:OLAPAttribute name="Customer" dataField="customer"/>
              <mx:OLAPHierarchy name="CustomerHier" hasAll="true">
                  <mx:OLAPLevel attributeName="Customer"/>
              </mx:OLAPHierarchy>
          </mx:OLAPDimension>
         
          <mx:OLAPDimension name="ProductDim">
              <mx:OLAPAttribute name="Product" dataField="product"/>
              <mx:OLAPHierarchy name="ProductHier" hasAll="true">
                  <mx:OLAPLevel attributeName="Product"/>
              </mx:OLAPHierarchy>
          </mx:OLAPDimension>

       

          <mx:OLAPDimension name="QuarterDim">
              <mx:OLAPAttribute name="Quarter" dataField="quarter"/>
              <mx:OLAPHierarchy name="QuarterHier" hasAll="true">
                  <mx:OLAPLevel attributeName="Quarter"/>
              </mx:OLAPHierarchy>
          </mx:OLAPDimension>
         
          <mx:OLAPMeasure name="Revenue"
              dataField="revenue"
              aggregator="SUM"/>
      </mx:OLAPCube>
          <mx:Panel title="OLAPCube Control Example"
              height="75%" width="75%" layout="horizontal"
              paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

       

              <mx:OLAPDataGrid id="myOLAPDG" width="100%" height="100%" variableRowHeight="true" wordWrap="true"/>
          </mx:Panel>
      </mx:Application>

       

      Regards,
      Alex