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

Re: [ydn-javascript] Re: Paginator Links

Expand Messages
  • Satyam
    I m sorry I didn t think to go beyond the last record I just went to the last and that works fine. So, I did go to the last record and then one beyond and,
    Message 1 of 14 , Oct 12, 2007
      I'm sorry I didn't think to go beyond the last record I just went to the
      last and that works fine. So, I did go to the last record and then one
      beyond and, indeed, it has several errors. I also want to apologize to
      Jerry, I wasn't serious in my replies to him.

      So, let me fix that, the example has several bugs.

      1) The php back end has one, which is the one that causes the "data error".
      When it is asked for a range of records beyond what it can deliver, it
      returns, as part of the reply:


      and it should return:


      This is due to a failure to initialize variable $data before its first use,
      right before the loop:

      $data = array(); // <== this is the missing line
      for($i=$startIndex; $i<($lastIndex); $i++) {
      $data[] = $allRecords[$i];

      2) the example file dt_serverpagination_source.html has a misspelled

      rowsThispage which should be: rowsThisPage

      Anyway, correcting this would make a different error. The properties of
      this.myDataTable.get("paginator") are not updated correctly. After all, for
      all the client knows, the totalRecords is always calculated based on the
      length of the current recordset so, even if you try to update it via the
      updatePaginator method, this particular variable won't be updated and will
      always be 25 or less, the actual number of records the client knows about.

      3) Anyway, the argument passed to updatePaginator is wrong. It tries to set
      a setting totalResults, which does not exist, instead of totalRecords. The
      problem is that method updatePaginator only updates values of already
      existing properties, it does check that the property actually exists before
      setting it simply before it checks for hasOwnProperty to skip over method
      toJSONString and so it also skips over any other variable that you would
      want to add.

      So, we cannot set totalRecords because it is calculated and we cannot set
      totalResults because it rejects it. By the time it gets to check whether it
      accepts a further click, once fixed the misspelling of rowsThisPage, it
      never succeeds since it won't ever know it has more than 25.

      4) The whole idea of using the paginator variables is not a good one. The
      paginator variables have a life of their own with too many side-effects
      which you have to work around and, in the end, confuse the reader to no
      avail. The best is to simply declare the variables local to the example
      main function:

      YAHOO.example.ServerPagination = new function() {
      var totalRecords, recordsReturned , startIndex , endIndex ,
      rowsPerPage = 25;

      and make all the calculations based on them.

      5) The last of those variables rowsPerPage fixes another issue. Once you
      get to the end, the last page will not have 25 records on that page. When
      you go back, instead of going 25 records at a time, it will go back by
      whatever number of records got in the last page. Since in the last page you
      get 22 records, it is barely noticeable but if the remainder was a single
      record, that would be really bad.

      6) Finally, the 'next' link should not be even enabled. This is due to the
      following line:

      YAHOO.util.Dom.get("nextLink").innerHTML =
      (endIndex >= totalRecords) ? ">" :
      "<a href=\"#next\" alt=\"Show next items\">></a>";

      Since records are zero based, endIndex for the last record is one less than
      the record count so the comparison always fails. It should read:

      YAHOO.util.Dom.get("nextLink").innerHTML =
      (endIndex + 1 >= totalRecords) ? ">" :
      "<a href=\"#next\" alt=\"Show next items\">></a>";

      I filed the errors and the fixed file to SourceForge:



      ----- Original Message -----
      From: "y_lsmith" <lsmith@...>
      To: <ydn-javascript@yahoogroups.com>
      Sent: Thursday, October 11, 2007 6:59 PM
      Subject: [ydn-javascript] Re: Paginator Links

      > --- In ydn-javascript@yahoogroups.com, "jerry_gagliano"
      > <jerry.gagliano@...> wrote:
      > http://developer.yahoo.com/yui/examples/datatable/dt_serverpagination_source.html
      >> go to the end of the the records. You will get a data error.
      > Jerry,
      > This indeed looks like a bug at least in the example, if not the
      > underlying code. Please submit the bug to sourceforge and we'll take
      > care of it.
      > We try to keep the examples in proper working order as the code
      > evolves, but as you've shown, sometimes things slip through the
      > cracks. Thanks for keeping us honest!
      > Regard,
      > Luke
      > Yahoo! Groups Links
      > --
      > No virus found in this incoming message.
      > Checked by AVG Free Edition.
      > Version: 7.5.488 / Virus Database: 269.14.7/1062 - Release Date:
      > 10/10/2007 17:11
    Your message has been successfully submitted and would be delivered to recipients shortly.