9 Replies Latest reply on Oct 7, 2009 4:22 PM by Matt Le Fevre

    What event should I use to grab the record count of a DataGrid?

    RedOctober57 Level 1

      I have a "Go" button on a search form.  It works correctly, fetching records from a CF data service into a data bound DataGrid.  However, using the code shown below, the record count always shows zero.  I've tried putting the "..Provider.length" line shown below, into various events on the grid, so that it will always update the count at the correct time, but I get "null" object errors at run time. There seems to be no event that fires "AfterDataLoad".

       

                  protected function btnGo_clickHandler(event:MouseEvent):void
                   {
                       getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);
                       tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;    //  This always returns zero.  Why?
                   }

        • 1. Re: What event should I use to grab the record count of a DataGrid?
          Gregory Lafrance Level 6

          You should put that in the event handler processing data returned from the data source.

           

          If this post answered your question or helped, please mark it as such.

          1 person found this helpful
          • 2. Re: What event should I use to grab the record count of a DataGrid?
            RedOctober57 Level 1

            Hi Greg, thanks for the quick answers.  I don't follow this last one however.  My CF function, as far as I know, can only return one result, and that is the data records coming back from the SQL statement.  I was thinking I would like to return two things... the data records, and the count (like you can do in 3GLs) but I don't see how this can be done.  Do you have a code snippet?

            • 3. Re: What event should I use to grab the record count of a DataGrid?
              RedOctober57 Level 1

              I can't seem to find any "After..." events, that would ensure that all data had been loaded and the object was ready for use/display.  Every event I try to use gives me an error, or zero records (when I know there are many records).

              • 4. Re: What event should I use to grab the record count of a DataGrid?
                RedOctober57 Level 1

                For example, this doesn't work.  The grid is told to loaded data on line 1, but this must just be only a message send to the Flash Player 10, because the processing doesn't stop and wait for the loading of data to complete, it just continues on to line 2, at which point '...Provider.length' is always zero the first time through.   So... the NEXT time the user clicks the Go button, line 2 is processed for the DataGrid which is holding data from the PREVIOUS search, so it updates the tabSbjs.label with the count from the previous search, not the current search.  The count of records is always for the previous data set.

                 

                            protected function btnGo_clickHandler(event:MouseEvent):void
                            {
                1               getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);  // edtSrch.text
                2               tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;                                                                            
                            }

                 

                 

                All I'm trying to do is (which seems like a very difficult thing to do in FB4):

                 

                -Display a DataGrid popluated with data records

                -Display a count of how many records are in the data grid

                 

                If I rely on CF9 functions, which can only return a single value, then I have to make two CF9  functions, with the exact same SQL, one that returns data, and one that returns a count of the records.... which is non-sensicle.

                 

                There must be a simple way to do this, but I'm going around in circles.

                • 5. Re: What event should I use to grab the record count of a DataGrid?
                  Matt Le Fevre Level 4

                       The program i'm working on does pretty much exactly the same as yours, except mine works and does return a correct return count on a search!

                   

                       At a guess;

                   


                              protected function btnGo_clickHandler(event:MouseEvent):void
                              {
                  1               getSBJsResult.token = baa_data_svc.getSBJs(cmbSrch.text);  // edtSrch.text

                   

                                  grdSBJs.dataProvider.refresh();
                  2               tabSbjs.label = 'Subjects: ' + grdSBJs.dataProvider.length;                                                                             
                              }

                   

                  1 person found this helpful
                  • 6. Re: What event should I use to grab the record count of a DataGrid?
                    RedOctober57 Level 1

                    It came to me in a dream... no, actually it was the "data binding" section of one of the early training videos.  Thinking in an OOP way, I just followed the video and it solved the problem.  I data bound the provider length to the canvas label, and it works as expected now.

                     

                    <mx:Canvas label="Subjects: {grdSBJs.dataProvider.length}"    ...

                    • 7. Re: What event should I use to grab the record count of a DataGrid?
                      RedOctober57 Level 1

                      Hmmm... the refresh didn't help, but I can see where you are going with this Griz.  See my other post, I solved the problem.  However I STILL need to set the first item to selected... which is in another post.

                      • 8. Re: What event should I use to grab the record count of a DataGrid?
                        RedOctober57 Level 1

                        Here's another solution:

                         

                        Use the "updateComplete" event.  At the point inside the "updateComplete" event, the object is initialized, data is loaded and you can get length, and set indexitem...all good.

                         

                        I was looking for an event named "After....".    (Delphi and MIDAS experience)

                        • 9. Re: What event should I use to grab the record count of a DataGrid?
                          Matt Le Fevre Level 4

                          RedOctober57 wrote:

                           

                          However I STILL need to set the first item to selected... which is in another post.

                           

                          just do on creation;

                           

                          grdSBJs.selectedIndex = 0;

                           

                          or do you mean something else