1 Reply Latest reply on Oct 5, 2007 12:53 AM by Newsgroup_User

    CF8 get cfgrid totalrowcount with ajaxonload() function

    Level 7
      i have a cfgrid bind to a cfc which returns a structure (a
      queryConvertForGrid() applied to a query resultset)
      the grid works fine.

      i want to add a line to the cgid's footer "XX total records found". and
      while i can add the text 'total records found', i can't seem to be able
      to get the number of records.
      i am using ajaxonload() call to the following js function to get this data:

      showTtlrows = function(){
      var mygrid = ColdFusion.Grid.getGridObject('resultsGrid');
      var mydata = mygrid.getDataSource();
      var ttlrecords = mydata.getTotalCount();
      //var ttlrecords = mydata.totalLength;
      alert(ttlrecord);

      the alert() call there is just for easy testing. it returns 0 right now
      and 'undefined' if i use the other ttlrecords definition in the function.
      the alert always pops up over an empty grid shell... the grid is there
      but it is not populated with data yet....

      NOTE: if the above function is called with an onclick event of a button,
      it work just fine and alerts correct number of returned records...

      Q:
      is there a way to return the number of records with ajaxonload() or
      similar method, without a button click? the ajaxonload(), which i
      thought should work, seems to fire too early, before the data is loaded
      into the grid... is this because of the grid being bound to a cfc? (i am
      trying to bind it to a js instead but am having separate issues with
      that...)

      any help will be very much appreciated...

      --

      Azadi Saryev
      Sabai-dee.com
      http://www.sabai-dee.com
        • 1. Re: CF8 get cfgrid totalrowcount with ajaxonload() function
          Level 7
          Brian Kotek on houseoffusion's CF-Talk mailing list has helped me figure
          this one out.

          you can't do it with a cfgrid bound to a cfc. you must bind it to a
          javascript using cfajaxproxy.
          after that it is rather trivial [well, looking back at it, it is :)] :

          <cfajaxproxy cfc="path.to.cfc" jsclassname="results">
          <script>
          getSearchResults = function(page,pagesize,sortcol,sortdir){
          var sr = new results();
          result = sr.yourcfcmethodname(page,pagesize,sortcol,sortdir);
          document.getElementById('ttlrows').innerHTML = result.TOTALROWCOUNT;
          return result;
          }
          </script>

          result.TOTALROWCOUNT in the above script holds the total number of
          records returned by the query in the cfc.
          i am displaying it in a <span>, but you can do whatever you want with it...

          the actual cfgrid code looks something like this:

          <cfgrid format="html"
          name="myGrid"
          bind="javascript:getSearchResults({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgri dsortdirection})"
          bindonload="true" ...>
          ....
          </cfgrid>

          that's it! cheers Brian Kotek!

          Azadi Saryev