Pagination SAP UI5将实施;请转到";表上的特定页面

Pagination SAP UI5将实施;请转到";表上的特定页面,pagination,sapui5,Pagination,Sapui5,我是SAP UI5开发的新手。目前该表正在使用“growing”和“growingThreshhold”,用户可以点击更多查看下一页的数据。由于该表中有数千个数据,用户需要花费大量时间再次单击以加载下一页数据。我们尝试实现一个功能,用户可以输入页码,然后单击按钮并转到特定页面 <Table id="genTable" growing="true" growingThreshold="60" fixedLayout="fa

我是SAP UI5开发的新手。目前该表正在使用“growing”和“growingThreshhold”,用户可以点击更多查看下一页的数据。由于该表中有数千个数据,用户需要花费大量时间再次单击以加载下一页数据。我们尝试实现一个功能,用户可以输入页码,然后单击按钮并转到特定页面

<Table id="genTable" growing="true" growingThreshold="60" fixedLayout="false" selectionChange="onHandleSelectChange"
    backgroundDesign="Solid" updateFinished="onHandleGeneratorQueueUpdateFinished">
我尝试的另一种方法是使用bindItems,它调用send请求到odata服务,但它没有添加参数top和skip参数

oTable.bindItems({
    path: "/ViewQueueSet",
    model: "sapmodel",
    filters: [new Filter("RoleCode", FilterOperator.EQ, "G")],
    template: this.oGenQueueTemplate,
    //   urlParameters: {
    //  "$top": top,
    //  "$skip": count
    // },
    parameters: {
        "$top": top,
        "$skip": count
    }
});

关于如何实现这个功能,有人有任何想法吗?

在我详细讨论之前,请考虑使用其他控件和/或UX模式。想象一下,在后端和用户请求中有数千或数百万个元素滚动到第929页=>对于响应表(sap.m.table),您需要将所有元素加载到该页。也许过滤或者一些完全不同的方法是正确的

正确的方法是获取listbinding并要求它加载更多元素。如何询问绑定,也可能取决于绑定的类型

oTable = ... // get a reference on table
oItemsBinding = oTable.getBinding("items");
oItemsBinding.getLength() // will give you total number of elements
oItemsBinding.isLengthFinal() // will tell you if the length is final
oItemsBinding.getCurrentContexts() // will give you array of all loaded contexts.
现在,请讲几句话的长度,长度为最终长度。如果您有一个知道对象总数的绑定实现(例如json,因为它将所有元素加载到客户端,或者OData,如果cont是在后端实现的),那么getLength将告诉您对象总数

如果后端未实现计数功能,则一旦到达列表末尾,长度将变为最终长度(后端提供的元素少于所需的元素-例如,top=10,skip=90返回10个元素=>length 100,而不是final;top=10,skip=100返回4个元素=>length=104变为最终长度)

现在,您可以看看各种绑定实现。但要注意的是,有很多事情要考虑(增长方向向上/向下),至少你不需要考虑过滤/排序——因为这是绑定的一部分。 在
sap.m.Table
(或者更准确地说,在
sap.m.ListBase
)中有一个很好的(私有)特性,它被称为
growtingEnablement
。您可以这样使用它:

// dont forget if _oGrowingDelagate is not undefined or similar
oTable._oGrowingDelegate.requestNewPage()
这将再加载一个页面=>如果要一次性加载多个页面,可以从读取此方法的开始

您还可以做一个简单的技巧:

// assume you have 20 elements per page (default) 
// and want to get to 7th page (elements 121 - 140) 

// ckecks for 7th page exists and 7th page not yet loaded are omitted

oTable.setGrowingThreshold(70) // half of 140, so following load will load second page => 71 to 140
oTable._oGrowingDelegate.requestNewPage() // this will load the second page 71 - 140

// once loading is finished (take care of asynchronity) 

oItemsBinding.attachEventOnce("dataReceived", function(oEvent){
   // reset the growing threshold to 20 
   oTable.setGrowingThreshold(20) 

   // scroll to first element of 7th page (index 120, since count starts from 0)
   oTable.scrollToInex(120)
})


谢谢你的回复。我可以根据您的上述评论加载项目。唯一的问题是oTable.scrollToIndex(121)不起作用。你知道为什么吗?如果项目121确实存在,它应该可以工作。(请注意,第121项有索引120,因为这里的计数从0开始-我刚刚修复了示例索引应该是正确的并且存在于列表中。下面是我的当前代码。计数是跳过计数。无论返回到页面还是前进到页面,scrollToIndex都无效。如果(topsPageNumbercheck first,如果您已经加载了所需的元素。如果是,则不会向后端发送任何数据请求,也不会触发任何
dataReveived
事件,因此包含scrollToIndex的处理程序将不会执行。在第一种情况下,数据已经存在,我直接调用scrollToIndex,而没有将其放入dataRecei中。)在第二种情况下,我需要请求新页面,然后在dataReceived中调用scrollToIndex。在这两种情况下,scrollToIndex都不起作用。
// dont forget if _oGrowingDelagate is not undefined or similar
oTable._oGrowingDelegate.requestNewPage()
// assume you have 20 elements per page (default) 
// and want to get to 7th page (elements 121 - 140) 

// ckecks for 7th page exists and 7th page not yet loaded are omitted

oTable.setGrowingThreshold(70) // half of 140, so following load will load second page => 71 to 140
oTable._oGrowingDelegate.requestNewPage() // this will load the second page 71 - 140

// once loading is finished (take care of asynchronity) 

oItemsBinding.attachEventOnce("dataReceived", function(oEvent){
   // reset the growing threshold to 20 
   oTable.setGrowingThreshold(20) 

   // scroll to first element of 7th page (index 120, since count starts from 0)
   oTable.scrollToInex(120)
})