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

发布于 2024-08-25 16:35:51 字数 1982 浏览 8 评论 0原文

我有一个带有 AJAX 分页的 YUI DataTable (YUI 2.8.0r4)。表中的每一行都链接到详细信息/编辑页面,我想从该详细信息页面链接回包含详细信息页面中的记录的列表页面。所以我必须 a) 正确偏移 AJAX 数据 b) 告诉 YAHOO.widget.Paginator 选择哪个页面。

根据我对 YUI API 文档的阅读,我必须传入 initialPage 配置选项。我已经尝试过这样做,但它不需要(来自 AJAX 的数据正确偏移,但分页器认为我在第 1 页,因此单击“下一步”会将我从第 6 页带到第 2 页。

我是什么没有做(或做错了)?

这是我的数据表构建代码:

(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;
  };
})();

I have a YUI DataTable (YUI 2.8.0r4) with AJAX pagination. 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.

According to my reading of the YUI API docs, I have to pass in the initialPage configuration option. 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 e.g. page 6 to page 2.

What am I not doing (or doing wrong)?

Here's my DataTable building code:

(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;
  };
})();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饮惑 2024-09-01 16:35:51

来自 YUI Paginator 文档:

setPage void setPage ( newPage ,
silent ) 将当前页面设置为
如果可能的话提供页码。

参数:
newPage 新页码
沉默是否强制避免发射
更改请求事件

返回:无效

setPage 方法可用于强制 YUI 分页器当前页面。
第二个参数“”可能对您有用,因为您不希望重新加载 ajax 数据。

From YUI Paginator Doc:

setPage void setPage ( newPage ,
silent ) Set the current page to the
provided page number if possible.

Parameters:
newPage the new page number
silent whether to forcibly avoid firing the
changeRequest event

Returns: void

the setPage method can be used to force YUI paginator current page.
the second parameter "<silent>" may be useful to you since you don't want the ajax data to be reloaded.

我的鱼塘能养鲲 2024-09-01 16:35:51

如果您想将分页器初始化到不同的页面,您还需要为totalRecords提供一个(临时)值。此论坛主题提供了更多详细信息:

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

If you want to initialize the Paginator to a different page, you also need to provide a (temporary) value for totalRecords. This forum thread provides more detail:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文