计算 CurrentGroup 的公式是什么

发布于 2024-07-13 08:19:45 字数 462 浏览 4 评论 0原文

尝试找出一个方程式来获取页面当前所在的组(如果它们按如下方式分组)。

变量:

PageSize = 5
PageIndex = 21
GroupSize = 5
TotalItems = 1000
CurrentPage = PageIndex + 1

查找:

**CurrentGroup = ?**

如果有 1000 个项目,并且组大小为 5,则有 200 个组(TotalItems / GroupSize)。 这意味着 CurrentPage 22 必须位于第 5 组

Group 1: 1 2 3 4 5
Group 2: 6 7 8 9 10
Group 3: 11 12 13 14 15
Group 4: 16 17 18 19 20
Group 5: 21 22 23 24 25

Trying to figure out an equation to get the current group a page would be in if they were grouped like below.

Variables:

PageSize = 5
PageIndex = 21
GroupSize = 5
TotalItems = 1000
CurrentPage = PageIndex + 1

Find:

**CurrentGroup = ?**

If there are 1000 items and you have a group size of 5 then there are 200 groups (TotalItems / GroupSize). This means that CurrentPage 22 must land in group 5

Group 1: 1 2 3 4 5
Group 2: 6 7 8 9 10
Group 3: 11 12 13 14 15
Group 4: 16 17 18 19 20
Group 5: 21 22 23 24 25

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

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

发布评论

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

评论(2

狠疯拽 2024-07-20 08:19:45

配方

1+floor((CurrentPage-1)/GroupSize)

测试

1 -> 1 
.. 
5 -> 1 
6 -> 2 
.. 
9 -> 2
..
22 -> 5

Formula

1+floor((CurrentPage-1)/GroupSize)

Test

1 -> 1 
.. 
5 -> 1 
6 -> 2 
.. 
9 -> 2
..
22 -> 5
流云如水 2024-07-20 08:19:45

我认为这就是您要问的 -

假设整数数学:

 page = ( item / ItemsPerPage ) + 1; // depends if 0 based.
 pageIndex = item % ItemsPerPage;
 group = ( page / GroupSize );

Page 是您要查找的页面

pageIndex 是它在目标页面

上的位置 em> 是基于 GroupSize 的实际组。

本质上,您只是添加了另一个级别的分页,因此与分页相同的数学原理。

I think this is what you were asking --

Assumes integer math:

 page = ( item / ItemsPerPage ) + 1; // depends if 0 based.
 pageIndex = item % ItemsPerPage;
 group = ( page / GroupSize );

Page is the page you're seeking

pageIndex is it's position on the destination page

group is the actual group it fits in based on GroupSize

In essence, you're just adding another level of paging so the same math works as paging.

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