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

Yui Server Side Pagination Woes

Expand Messages
  • Amy
    I am using some sample code written by satyam to display a dynamic datatable. The table has an unknown number of columns because our reports are flexible. This
    Message 1 of 2 , Jul 31, 2009
    • 0 Attachment
      I am using some sample code written by satyam to display a dynamic datatable. The table has an unknown number of columns because our reports are flexible.

      This is the sample code:

      http://www.satyam.com.ar/yui/2.5.0/dt_serverdriven.html

      The problem I am having is that the total number of records is being returned, but the paginator is not rendering correctly to show this. Instead, it always shows 1 page, with just the first page of results.

      My code can be seen running here:
      http://amy.sleeplms.net/index.php?module=lms&func=newlist&entityID=5

      or here:
      http://amy.sleeplms.net/index.php?module=lms&func=newlist&entityID=7

      Using firebug on the first url, I see the following JSON response
      ===========

      {"recordsReturned":20,"totalRecords":32,"startIndex":"0","sort":"Last","dir":"ASC","records":[{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=328","Last":"Anotra","First":"Stuart","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=321","Last":"Bacon","First":"Frances","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=212","Last":"Blumberg","First":"Neal","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=280","Last":"Brown","First":"Timothy","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=205","Last":"Bug","First":"June","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=149","Last":"Calendar","First":"Marie","HomePhone":"215-555-6767"},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=229","Last":"Clark","First":"Kimi","HomePhone":"404-555-6231"},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=214","Last":"Clee","First":"Wendy","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=195","Last":"Day","First":"Rainee","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=192","Last":"Doe","First":"John","HomePhone":"555-555-5555"},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=154","Last":"Duck","First":"Fluffy","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=187","Last":"Franklin","First":"Benjamin","HomePhone":"456-789-0000"},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=198","Last":"Franklin","First":"Ben","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=342","Last":"Green","First":"Lee","HomePhone":"678-555-4532"},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=185","Last":"Harner","First":"Cheryl","HomePhone":"215-555-7878"},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=326","Last":"James","First":"Henry","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=236","Last":"Johnson","First":"Marvin","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=253","Last":"Jordan","First":"Hilary","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=341","Last":"Jordan","First":"Hilary","HomePhone":null},{"editurl":"http:\/\/amy.sleeplms.net\/index.php?module=lms&func=edit&instance=325","Last":"just","First":"Came","HomePhone":null}],"meta":[{"key":"Last","label":"Last","sortable":true},{"key":"First","label":"First","sortable":true},{"key":"HomePhone","label":"Home Phone:","sortable":true}]}

      ===========
      Based on that response, I would expect the paginator to be showing two pages.

      The relevant code in the script (from the sample code)

      myDataTable = new YAHOO.widget.DataTable(
      'dynamicdata',
      [{key:'this_is_just_a_fake_column_key_to_keep_the_system_happy',label:' '}],
      myDataSource,
      {
      // We request a first batch of 20 records, starting at zero,
      // and we also request meta information which describes the data
      initialRequest: 'module=lms&func=entitylist&startIndex=0&results=20&entityID='+entityID,

      // We set pagination with 20 records per page
      paginated: true,
      paginator: new YAHOO.widget.Paginator({
      rowsPerPage:20
      }),

      paginationEventHandler: YAHOO.widget.DataTable.handleDataSourcePagination,


      generateRequest: function (oData, oDataTable) {
      var newRequest = 'module=lms&func=entitylist&startIndex=' + oData.pagination.recordOffset + '&results=' + oData.pagination.rowsPerPage+'&entityID='+entityID;
      var sortedBy = oDataTable.get('sortedBy');
      if (sortedBy) {
      newRequest += '&sort=' + sortedBy.key + '&dir=' + ((sortedBy.dir == 'yui-dt-asc')?'desc':'asc');
      }
      return newRequest;
      }
      }
      );
    • Amy
      I got it. The problem was that once again, YUI changed dramatically between one version and the next. This is my main complaint about YUI. They make it
      Message 2 of 2 , Aug 5, 2009
      • 0 Attachment
        I got it. The problem was that once again, YUI changed dramatically between one version and the next.

        This is my main complaint about YUI. They make it impossible to upgrade large applications with any consistency because they don't make their updates backwards compatible.
      Your message has been successfully submitted and would be delivered to recipients shortly.