当用户更改页面大小(每页项)时,我正在尝试设置默认页码的值
我正在谈论secenarion,我在第10页的第10页上有10行,然后将其更改为25,它将更新为第4页,然后将更改为50,将更新为第2页。
另一种方法是,当我在第100页的第2页上,然后切换到50行时,我将在第3页上结束,然后更改为每页25个项目-第5页和第10页第11页
我以为
defaultPageNo = round(((currentPageNo * prevRowSize) / currentRowSize )) + 1;
可以使用,但每页向下只能从100个项目开始。
任何提示如何使其看起来正确?
答案 0 :(得分:1)
tldr
nextPage = floor(oldPage * oldLimit / nextLimit)
或更好
nextPage = floor(offset / nextLimit)
一种“标准”的思维方式是根据offset
,limit
offset
是您跳过的元素数(更确切地说是您所在元素的索引)limit
是您显示的元素数量在您的词汇表中,
pagination
是limit
currentPage = floor(offset / limit)
当您更改分页(也称为limit
)时,您不想更改offset
,只有页面,并且(分区中)确实不知道限制是否增加。
现在,因为偏移量是不变的,我们肯定想知道它。
nextPage = floor(offset / nextLimit)
if currentPage == k, then offset == k * limit + r (k,r integers, r < limit)
由于我们要显示第一个,所以我们将说offset = k * limit + 0 = currentPage * limit
最后
nextPage = floor(offset / nextLimit) = floor(oldPage * oldLimit / nextLimit)
例如
const changePagination = (old, newLimit) => {
const next = { page: Math.floor(old.page * old.limit / newLimit), limit: newLimit }
console.log(next, 'next display at offset:', next.page * next.limit)
return next
}
let old = { page: 238, limit: 1 } // make some coll
old = changePagination(old, 1)
old = changePagination(old, 2)
old = changePagination(old, 4) // notice we show a few "new" elements
old = changePagination(old, 8)
old = changePagination(old, 5)
old = changePagination(old, 11)
console.log('ill stuff')
old = changePagination({ page: 60, limit: 1 }, 21)
old = changePagination(old, 20)
old = changePagination(old, 21)
old = changePagination(old, 20)
old = changePagination(old, 21) // first offset is 0 ?!! while initial is 60
因此,如果您有偏移量,请保持,而不要从旧分页中猜测