简体   繁体   English

如何设置YUI2分页器选择第一页以外的页面?

[英]How do I set YUI2 paginator to select a page other than the first page?

I have a YUI DataTable (YUI 2.8.0r4) with AJAX pagination. 我有一个带有AJAX分页的YUI数据表(YUI 2.8.0r4)。 Each row in the table links to a details/editing page and I want to link from that details page back to the list page that includes the record from the details page. 该表中的每一行都链接到一个详细信息/编辑页面,我想从该详细信息页面链接回包含该详细信息页面中的记录的列表页面。 So I have to a) offset the AJAX data correctly and b) tell YAHOO.widget.Paginator which page to select. 因此,我必须a)正确偏移AJAX数据,b)告诉YAHOO.widget.Paginator选择哪个页面。

According to my reading of the YUI API docs , I have to pass in the initialPage configuration option. 根据我对YUI API文档的阅读,我必须传递initialPage配置选项。 I've attempted this, but it doesn't take (the data from AJAX is correctly offset, but the paginator thinks I'm on page 1, so clicking "next" takes me from eg page 6 to page 2. 我已经尝试过了,但是没有用(来自AJAX的数据已正确偏移,但是分页器认为我在第1页上,因此单击“下一个”会将我从第6页转到第2页。

What am I not doing (or doing wrong)? 我在做什么(或做错了)?

Here's my DataTable building code: 这是我的DataTable构建代码:

(function() {
  var columns = [
    {key: "retailer",    label: "Retailer",    sortable: false, width: 80},
    {key: "publisher",   label: "Publisher",   sortable: false, width: 300},
    {key: "description", label: "Description", sortable: false, width: 300}
  ];

  var source = new YAHOO.util.DataSource("/sales_data.json?");
  source.responseType = YAHOO.util.DataSource.TYPE_JSON;
  source.responseSchema = {
    resultsList: "records",
    fields: [
      {key: "url"},
      {key: "retailer"},
      {key: "publisher"},
      {key: "description"}
    ],
    metaFields: { totalRecords: "totalRecords" }
  };

  var LoadingDT = function(div, cols, src, opts) {
    LoadingDT.superclass.constructor.call(
      this, div, cols, src, opts);
    // hide the message tbody
    this._elMsgTbody.style.display = "none";
  };
  YAHOO.extend(LoadingDT, YAHOO.widget.DataTable, {
    showTableMessage: function(msg) { 
      $('sales_table_overlay').clonePosition($('sales_table').down('table')).
        show();
    },
    hideTableMessage: function() { 
      $('sales_table_overlay').hide();
    }
  });

  var table = new LoadingDT("sales_table", columns, source, {
    initialRequest: "startIndex=125&results=25",
    dynamicData: true,
    paginator: new YAHOO.widget.Paginator({rowsPerPage: 25, initialPage: 6})
  });

  table.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
    oPayload.totalRecords = oResponse.meta.totalRecords;
    return oPayload;
  };
})();

From YUI Paginator Doc: 从YUI Paginator Doc:

setPage void setPage ( newPage , silent ) Set the current page to the provided page number if possible. setPage void setPage(newPage,Silent)如果可能,将当前页面设置为提供的页码。

Parameters: newPage the new page number silent whether to forcibly avoid firing the changeRequest event 参数:newPage新页码无提示是否强制避免触发changeRequest事件

Returns: void 返回:void

the setPage method can be used to force YUI paginator current page. setPage方法可用于强制YUI分页器当前页面。 the second parameter "<silent>" may be useful to you since you don't want the ajax data to be reloaded. 第二个参数“ <silent>”可能对您有用,因为您不希望重新加载ajax数据。

If you want to initialize the Paginator to a different page, you also need to provide a (temporary) value for totalRecords. 如果要将Paginator初始化为其他页面,则还需要为totalRecords提供一个(临时)值。 This forum thread provides more detail: 该论坛主题提供了更多详细信息:

http://yuilibrary.com/forum/viewtopic.php?f=90&t=1913&start=0&hilit=initialPage http://yuilibrary.com/forum/viewtopic.php?f=90&t=1913&start=0&hilit=initialPage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM