4 Replies Latest reply on Aug 25, 2007 7:10 AM by aceinc

    datagrid finished loading event.

    aceinc Level 1
      Is there an event that will reliablbly capture the end of loading a datagrid?

      I am using Alex's FooterDataGrid to create a footer on a grid, and what I can't figure out how to do is fire the "invalidateDisplayList();" in order to recalculate the totals after I get new data from the backend. I use;

      grdVendorSummary.dataProvider = acVendorSummary;

      to repopulate the datagrid when the user requires, and it works, and the footer gets filled the first time it is called. Everytime after that the footer does not get filled. I pu a button on the panel that executes "invalidateDisplayList();" and it recalculates my totals which are done in a function called by a labelFunction. It will also recalculate the toatals if I click anywhere in the grid.

      I cannot, however, figure out how to get it to fire automatically every time the grid is repopulated.

      As always all help is appreciated.

      Paul
        • 1. Re: datagrid finished loading event.
          TheTyrant
          What if instead of using labelFunction, you just use label. Set it equal to a [Bindable] property, then when you re-populate the grid, call a "recalculateGridTotal()" function which sums up the grid and assigns the value to the bindable property.
          • 2. Re: datagrid finished loading event.
            aceinc Level 1
            The question is how do I trap the event that says the grid is finished populating?

            For the moment I am destroying the grid, and reinstantiating it, and that works. A little kludgy, but it works.

            Paul
            • 3. Re: datagrid finished loading event.
              chris.huston.t10 Level 3
              Are you using HTTPService to get the data that populates your grid? If so, you can set the result event to trigger a function that can recalculte the totals based on the new data. Post your code for getting your data from your backend if you need help setting the result event.

              Vygo
              • 4. Re: datagrid finished loading event.
                aceinc Level 1
                Below is the "results" function that populates the grid;

                private function vendorSearchResults(event:Event):void
                {
                if(Number(vendorSearch.lastResult.DataSet.recordcount) == 0)
                {
                Alert.show("No matching records", "Sorry",Alert.OK, this, null,Images.stopIcon);
                }
                else
                {
                currentState = 'VendorResults';
                if(Number(vendorSearch.lastResult.DataSet.recordcount) > 1)
                {
                acVendorSummary = vendorSearch.lastResult.DataSet.VendorSummary;
                }
                else
                {
                acVendorSummary.removeAll(); /* clear grid before adding the record.
                add a single record to the grid manually,
                this is because an ArrayCollection cannot
                be populated from a service call that contains
                only a single record
                */
                acVendorSummary.addItem({
                VENDOR_NUMBER:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_NUMBER,
                VENDOR_NAME:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_NAME,
                VENDOR_CLASSIFICATION:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_CLASSIFICATION ,
                VENDOR_STATUS:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_STATUS,
                VENDOR_TOTAL:vendorSearch.lastResult.DataSet.VendorSummary.VENDOR_TOTAL,
                TRANSACTION_COUNT:vendorSearch.lastResult.DataSet.VendorSummary.TRANSACTION_COUNT});
                acVendorSummary.refresh();
                grdVendorSummary.dataProvider = acVendorSummary;
                }
                }
                }

                Here is the mxml for one of the total cells;

                <dgf:FooterDataGridColumn headerText="Checks" textAlign="right" labelFunction="nbrFormatInteger" dataField="TRANSACTION_COUNT" width="50">
                <mx:DataGridColumn id="totChecks" dataField="TOTAL_CHECKS" labelFunction="sumAmount" textAlign="right" />
                </dgf:FooterDataGridColumn>

                Finallly the code to calculate the total;

                public function sumChecks(col:DataGridColumn):String
                {
                var totAmount:Number = 0;
                var n:int = acVendorSummary.length;
                for (var i:int = 0; i < n; i++)
                {
                totAmount += acVendorSummary [col.dataField];
                }
                return nbrFormat.format(totAmount);

                }

                The problem isn't recalculation, it seems to do that just fine, it just doesn't redisplay the totals portion of grid the second time through.