Loading ...
Sorry, an error occurred while loading the content.

getRecordSet().getLength() returns 0....when can I call this to get results?

Expand Messages
  • dufferdo25
    Hello all, I am using the DataTable with AutoComplete, thus when users type a string, the DataTable is filtered by the search string... I want to be able to
    Message 1 of 4 , Feb 28, 2008
    • 0 Attachment
      Hello all,
      I am using the DataTable with AutoComplete, thus when users type a
      string, the DataTable is filtered by the search string...
      I want to be able to dislay the Number of records returned.
      When I try the following:
      myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs,
      this.myDataSource, oConfigs);
      alert(myDataTable.getRecordSet().getLength());

      I get 0.

      Now if I do the following:
      YAHOO.util.Event.addListener(window, "unload", function() {
      var cnt = myDataTable.getRecordSet().getLength();alert(cnt);
      });

      I get a valid record count but obviously this is not useful (onunload).

      So, how and where can I use this effectively?
      TIA!
    • Satyam
      The data is read asynchronously by the DataSource so when you create the DataTable, you are just starting the communication with the server, a long time will
      Message 2 of 4 , Feb 28, 2008
      • 0 Attachment
        The data is read asynchronously by the DataSource so when you create the
        DataTable, you are just starting the communication with the server, a long
        time will pass (in computer time) until the reply eventually comes. In the
        meantime, the call to the DataTable constructor will have returned and you
        will read the recordset length which, at that point, well before the server
        has processed the reply, will report zero.

        Listen to either renderEvent (in 2.5) or refreshEvent (in previous
        versions). Then, the DataTable will be already on the screen and the length
        will be valid.

        Satyam

        ----- Original Message -----
        From: "dufferdo25" <dufferdo25@...>
        To: <ydn-javascript@yahoogroups.com>
        Sent: Thursday, February 28, 2008 6:04 PM
        Subject: [ydn-javascript] getRecordSet().getLength() returns 0....when can I
        call this to get results?


        > Hello all,
        > I am using the DataTable with AutoComplete, thus when users type a
        > string, the DataTable is filtered by the search string...
        > I want to be able to dislay the Number of records returned.
        > When I try the following:
        > myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs,
        > this.myDataSource, oConfigs);
        > alert(myDataTable.getRecordSet().getLength());
        >
        > I get 0.
        >
        > Now if I do the following:
        > YAHOO.util.Event.addListener(window, "unload", function() {
        > var cnt = myDataTable.getRecordSet().getLength();alert(cnt);
        > });
        >
        > I get a valid record count but obviously this is not useful (onunload).
        >
        > So, how and where can I use this effectively?
        > TIA!
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        > --
        > No virus found in this incoming message.
        > Checked by AVG Free Edition.
        > Version: 7.5.516 / Virus Database: 269.21.1/1302 - Release Date:
        > 27/02/2008 16:34
        >
        >
      • dufferdo25
        Thanks so much for that explanation. I cant seem to get this to work with my current implementation. Perhaps its because I declared myDataTable as global in
        Message 3 of 4 , Feb 29, 2008
        • 0 Attachment
          Thanks so much for that explanation.

          I cant seem to get this to work with my current implementation.
          Perhaps its because I declared myDataTable as global in scope?
          <script>
          var myDataTable;

          YAHOO.util.Event.addListener(window, "load", function() {
          YAHOO.example.XHR_XML = new function() {
          this.formatUrl = function(elCell, oRecord, oColumn, sData) {
          elCell.innerHTML = "<a href='" + oRecord.getData("url") +
          "' title='" + oRecord.getData("url") + "' target='_blank'>" + sData +
          "</a>";
          };

          var myColumnDefs = [
          {key:"title", label:"Name", sortable:true,
          formatter:this.formatUrl, width:400},
          {key:"lastAccessed", label: "Last Accessed",
          sortable:true, width:300},
          {key:"lastAccessedFrom", label: "Accessed from",
          sortable:true},
          {key:"popularity", label: "Popularity", sortable:true},
          {key:"hit_count",
          label:"Hits",formatter:YAHOO.widget.DataTable.formatNumber,
          sortable:true}
          ];

          this.myDataSource = new YAHOO.util.DataSource("AccessXML?");
          var response = this.myDataSource;
          this.myDataSource.connMethodPost = true;
          this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
          this.myDataSource.responseSchema = {
          resultNode: "Result",
          fields:
          ["title","lastAccessed","lastAccessedFrom","popularity",{key:"hit_count",parser:YAHOO.util.DataSource.parseNumber},"url"]

          };
          var oConfigs = {
          scrollable:true,
          height:"20em",
          initialRequest: "count=100"
          };

          myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs,
          this.myDataSource, oConfigs);
          };

          });
          YAHOO.util.Event.addListener(window, "onmouseout", function() {
          var cnt = myDataTable.getRecordSet().getLength();alert(cnt);
          });
          </script>

          The reason for this is because I have other functions that call
          myDataTable so I couldnt figure out how to get these functions to work
          without a global var.
          example of another function that reloads datatable with N records.
          function limitBy(_count) {
          var newRequest = "count=" + _count;
          myDataTable.getDataSource().sendRequest(newRequest,
          myDataTable.onDataReturnInitializeTable, myDataTable);
          }

          Any ideas?
        • Satyam
          Having myDataTable declared global should not be a problem, though it would be better if you declared it under YAHOO.example or a namespace of your own.
          Message 4 of 4 , Feb 29, 2008
          • 0 Attachment
            Having myDataTable declared global should not be a problem, though it would
            be better if you declared it under YAHOO.example or a namespace of your own.
            Instead of declaring it global, when you create it you say:

            YAHOO.example.myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs,
            this.myDataSource, oConfigs);

            Then, the table would be globally accessible but not in the global
            namespace. You would have to use the whole name for it everytime you refer
            to it, but you will have it accessible everywhere without taking any global
            space.

            I am not sure why would you try to read the length on such an unrelated
            event. I'm not sure what might make that event trigger, perhaps a random
            mouse movement from the user. The DataTable offers the renderEvent which
            will be fired everytime the DataTable is refreshed, either with new
            information of due to a sort, a record insertion or deletion or anything
            that might redraw the DataTable. I guess that reading the length more than
            once won't hurt.

            To requery the server, you might add the following method to the DataTable
            itself:

            YAHOO.widget.DataTable.prototype.requery = function(newRequest) {
            this.getDataSource().sendRequest((newRequest ===
            undefined?this.get('initialRequest'):newRequest),
            this.onDataReturnInitializeTable, this);
            };

            It is basically the same you did but encapsulated already within the
            DataTable as if it was a native method.

            Satyam


            ----- Original Message -----
            From: "dufferdo25" <dufferdo25@...>
            To: <ydn-javascript@yahoogroups.com>
            Sent: Friday, February 29, 2008 6:28 PM
            Subject: [ydn-javascript] Re: getRecordSet().getLength() returns 0....when
            can I call this to get results?


            > Thanks so much for that explanation.
            >
            > I cant seem to get this to work with my current implementation.
            > Perhaps its because I declared myDataTable as global in scope?
            > <script>
            > var myDataTable;
            >
            > YAHOO.util.Event.addListener(window, "load", function() {
            > YAHOO.example.XHR_XML = new function() {
            > this.formatUrl = function(elCell, oRecord, oColumn, sData) {
            > elCell.innerHTML = "<a href='" + oRecord.getData("url") +
            > "' title='" + oRecord.getData("url") + "' target='_blank'>" + sData +
            > "</a>";
            > };
            >
            > var myColumnDefs = [
            > {key:"title", label:"Name", sortable:true,
            > formatter:this.formatUrl, width:400},
            > {key:"lastAccessed", label: "Last Accessed",
            > sortable:true, width:300},
            > {key:"lastAccessedFrom", label: "Accessed from",
            > sortable:true},
            > {key:"popularity", label: "Popularity", sortable:true},
            > {key:"hit_count",
            > label:"Hits",formatter:YAHOO.widget.DataTable.formatNumber,
            > sortable:true}
            > ];
            >
            > this.myDataSource = new YAHOO.util.DataSource("AccessXML?");
            > var response = this.myDataSource;
            > this.myDataSource.connMethodPost = true;
            > this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
            > this.myDataSource.responseSchema = {
            > resultNode: "Result",
            > fields:
            > ["title","lastAccessed","lastAccessedFrom","popularity",{key:"hit_count",parser:YAHOO.util.DataSource.parseNumber},"url"]
            >
            > };
            > var oConfigs = {
            > scrollable:true,
            > height:"20em",
            > initialRequest: "count=100"
            > };
            >
            > myDataTable = new YAHOO.widget.DataTable("xml", myColumnDefs,
            > this.myDataSource, oConfigs);
            > };
            >
            > });
            > YAHOO.util.Event.addListener(window, "onmouseout", function() {
            > var cnt = myDataTable.getRecordSet().getLength();alert(cnt);
            > });
            > </script>
            >
            > The reason for this is because I have other functions that call
            > myDataTable so I couldnt figure out how to get these functions to work
            > without a global var.
            > example of another function that reloads datatable with N records.
            > function limitBy(_count) {
            > var newRequest = "count=" + _count;
            > myDataTable.getDataSource().sendRequest(newRequest,
            > myDataTable.onDataReturnInitializeTable, myDataTable);
            > }
            >
            > Any ideas?
            >
            >
            >
            >
            >
            >
            > Yahoo! Groups Links
            >
            >
            >
            >
            >
            > --
            > No virus found in this incoming message.
            > Checked by AVG Free Edition.
            > Version: 7.5.516 / Virus Database: 269.21.1/1303 - Release Date:
            > 28/02/2008 12:14
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.