简体   繁体   English

如何使用分页实现目录

[英]how to implement a catalog with pagination

I'm working on a catalog with pagination, I'm redirecting all my requests to an index file and making friendly urls from there, 我正在分页处理目录,我将所有请求重定向到索引文件,并从那里创建友好的网址,

my catalog has some filters to search products, when you apply some filters and then get into a product and click the back button in the browser, it goes to the catalog page and loses all the previously applied filters. 我的目录中有一些用于搜索产品的过滤器,当您应用一些过滤器然后进入产品并单击浏览器中的“后退”按钮时,它将转到目录页面,并且会丢失所有先前应用的过滤器。

I get the filter parameters through javascript and I send them through ajax via POST to my php controller. 我通过javascript获取过滤器参数,并通过POST通过ajax将其发送到我的php控制器。

How should I correctly implement this?? 我应该如何正确实施呢?

You need to grab the amount of data to filter, and in ajax you ll provide the boundaries on this pool. 您需要获取要过滤的数据量,并在ajax中提供此池的边界。

lets say an example : with a pool of 75 data rows, 30 results per page. 举个例子:一个有75个数据行的池,每页30个结果。 first you have to calculate your amount of pages, here ceil(75/30), so here you got 3 pages. 首先,您必须计算您的页面数量,在这里ceil(75/30),所以这里有3页。

if you are on page 1 and you display the results 1 to 30. You have to calculate the begining of your dataset, here 1 : ( (current_page-1)x number of result +1) so 0 x 30 +1 如果您在第1页上,并且显示结果1至30。则必须计算数据集的开头,此处为1 :(((current_page-1)x结果数+1)因此0 x 30 +1

on click on next page, you have to provide content for the second page, it means starting from (2-1)x30 + 1 : 31 在单击下一页时,您必须提供第二页的内容,这意味着从(2-1)x30 + 1:31开始

Last page, you start from (3-1)x30 + 1 : 61 最后一页,您从(3-1)x30 +1:61开始

each time you have to clear your data displayed on the js callback and display the new array you just got. 每次您必须清除js回调中显示的数据并显示刚得到的新数组时。

Hope it is clear. 希望清楚。

您可以将过滤器保存在Cookie中一小段时间。

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

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