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

Re: [ydn-javascript] Re: getRecordSet().getLength() returns 0....when can I call this to get results?

Expand Messages
  • 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 1 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.