3 Replies Latest reply on Oct 6, 2009 1:30 PM by kingquattro

    Get count from paging

    kingquattro Level 1

      Hey guys,

         I have a datagrid that get populated via DB, and I have paging turned on, with a count function.  But how do I get that count?  I would like to display the total count on the screen so user knows how many records are returned from db. I can't seem to figure this out, I have a feeling that I am missing something quite simple.  I see a call made to my count() function when the service is called, but can't figure out how to access that value returned.

       

      current setup:

      Beta 1,

      CF 8,

      MacBook, with Snow Leopard

       

      Thank you

      Jay

        • 1. Re: Get count from paging
          SunilAdobe Adobe Employee

          FB will automatically make a call to your count function initially to determine the number of records. For you to get the value, you could just use the dataprovider that you assigned to the datagrid like this

           

          <mx:Text text="{MyService_pagedResult.lastResult.length}"/>

           

          Or just make another service call (you can do this by choosing Bind to data for the text field and choose count method and FB will automatically generate the call for you)

           

          Thanks

          -Sunil

          • 2. Re: Get count from paging
            kingquattro Level 1

            Hi,

               So this works, but not what I was expecting.  What I want to display is as follows

             

                 (Displaying x of total)

             

                 Assuming that I have set my pageSize to 500, {MyService_pagedResult.lastResult.length} return total count part which I wasn't expecting. 

             

                 I was expecting lastResult.length to return number or records currently fetched from the db.  In this case then what is the use of count function call? Since lastResult.length already has total number of records that I am will end up with at the end, why make two distinct db calls and use up that clock cycle?  Sorry I am by no means an expert, just curious why this is the case, and want to understand whats happening behind the RPC call

             

                 So back to my problem how do I get the "x" part if lastResult.length is returning total count.  I tried to save lastResult in an array and I got an error something about pending result.  I can probably keep some local var, so count how many times service call is made, and then divide by total to get "x" but I is there an easier way?

             

            Thanks

            Jay

            • 3. Re: Get count from paging
              kingquattro Level 1

              OK, I think I may have answered my own question, but if someone could please confirm if I understand this correctly.

               

              case 1: When paging is enabled, with count function the length value in lastResult is overwritten with what count() function retunred

              case 2: When paging is enabled with out count function the length value is true length of the resultset, and an explicit call to count() is required to get total count.

               

              In either case two calls to db are made.  If you want true count of resultset in case 1, a bit of local var, and counting will get you the value of rows fetched so far.

               

              Thanks

              Jay