8 Replies Latest reply on Dec 16, 2009 6:39 AM by Jerry62712

    How do I get a record count?

    Jerry62712 Level 1

      I've got a dataprovider that points to the results of a query against an SQL Database.  That is pointed to a data grid.  How do I get the record count from the dataprovider or data grid?

        • 1. Re: How do I get a record count?
          PeakDigital Level 1

          I think you are referring to yourDataGrid.dataProvider.length

          • 2. Re: How do I get a record count?
            Jerry62712 Level 1

            All I got from "length" was 1.

             

            I have a grid with three rows of data in this case.  What I want to see is a count of "3" somewhere (or whatever is the true count).

             

            Here is the code I tried:

             

                    CURRENTCENSUS.text = dgSearchResults.dataProvider.length;

             

            Hopefully you can look at this and just say, "OMG, just change 'X' to 'Y' and it will work"

            • 3. Re: How do I get a record count?
              SHevenal776 Level 1

              You can accomplish this by accessing the "length" property of your

              datagrid dataprovider.

               

              So if you using an arraycollection called "dataP" for your datagrid

              dataprovider, you would access that property in action script like so:

               

              private var recordCount:int = dataP.length;

              • 4. Re: How do I get a record count?
                PhilipKeiter Level 2

                Jerry,

                 

                Do you have any filterFunction applied to the collection? If you do, you'll get the filtered length rather than the original length.

                 

                Thanks,

                Philip

                • 5. Re: How do I get a record count?
                  SHevenal776 Level 1

                  Could you post a bit more of your code?  Just need a little context to

                  nail down the issue.

                  • 6. Re: How do I get a record count?
                    Jerry62712 Level 1

                    The datagrid has this in the dataProvider entry:

                    public function handleResult(event:InvokeResultEvent):void {

                        SearchResult = event.result.xmlData as XML0;
                        var intRowsAffected:int = int(event.result.outRowsAffected as int);
                        if(SearchResult != null)
                        {
                            dmSearch = XML(SearchResult.document);
                            dgSearchResults.dataProvider = dmSearch.RecProcess;
                            CURRENTCENSUS.text = intRowsAffected.toString();
                        }
                        if(intRowsAffected == 0 ){
                            Alert.show("Error Saving Record", "Save Record Error");}
                        else if (intRowsAffected == 1) {
                            Alert.show("Record successfully saved.", "Save Record");
                        }
                        else {
                          //(-1) do nothing.
                        }
                    }
                    

                     

                    CURRENTCENSUS is the field I want to populate with the number of records that was returned.  Other tries included:

                            CURRENTCENSUS.text = dgSearchResults.dataProvider.length();
                    and that with "toString()".  Either gives an error and "length()" isn't a property of dataProvider apparently.  What does appear is "1" in CURRENTCENSUS which I take to be the number of dataProviders as there are 3 records in the grid.

                    • 7. Re: How do I get a record count?
                      RK...

                      Can you try like this,

                       

                      new XMLList(dataProvider).length()

                      • 8. Re: How do I get a record count?
                        Jerry62712 Level 1

                        You, sir, are a gentleman and a genius.  That worked.

                         

                        Thank you and all the others that have helped me reach this point!