antd自定義分頁器 自定義分頁器例項

2021-10-13 12:17:30 字數 2401 閱讀 4393

def __init__(self, current_page_num, all_count, request,per_page_num=2, pager_count=11):"""封裝分頁相關資料

:param current_page_num: 當前訪問頁的數字

:param all_count: 分頁資料中的資料總條數

:param per_page_num: 每頁顯示的資料條數

:param pager_count: 最多顯示的頁碼個數"""

'''進行判斷,如果輸入的是字串捕獲之後整回第一頁'''

try:

current_page_num=int(current_page_num)exceptexception as e:

current_page_num=1

"""如果輸入的是別的字元或者<1,直接給他第一頁資料"""

if current_page_num <1:

current_page_num=1

#進行資料的例項化

self.current_page_num =current_page_num

self.all_count=all_count

self.per_page_num=per_page_num#計算實際的總頁碼 商和餘 (divmod是內建函式)

all_pager,tmp =divmod(all_count,per_page_num)iftmp:

all_count= all_count+1self.all_pager=all_pager

self.pager_count=pager_count

#選擇當前頁數顯示左邊顯示5個右邊顯示5個36*

self.pager_count_half= int((pager_count - 1)/2)#儲存搜尋條件,deepcopy深拷貝,可以新增節點

importcopy

self.params=copy.deepcopy(request.get)'''起始頁和結束也的判斷

如果使用者在4頁,顯示的資料應該是30---40 也就是:current_page_num - 1 * per_page_num'''@propertydefstart(self):return (self.current_page_num - 1) *self.per_page_num

@propertydefend(self):return self.current_page_num *self.per_page_numdefpage_html(self):#如果總頁碼 < 11個:

if self.all_pager <=self.pager_count:#預設顯示就是第一頁

pager_start = 1pager_end= self.all_pager + 1

#總頁碼 > 11

else:#當前頁如果<=頁面上最多顯示11/2個頁碼

if self.current_page_num <=self.pager_count_half:

pager_start= 1pager_end= self.pager_count + 1

#當前頁大於5

else:#頁碼翻到最後

if (self.current_page_num + self.pager_count_half) >self.all_pager:

pager_start= self.all_pager - self.pager_count + 1pager_end= self.all_pager + 1

else:

pager_start= self.current_page_num -self.pager_count_half

pager_end= self.current_page_num + self.pager_count_half + 1page_html_list=

first_page= '

首頁' % (1,)

if self.current_page_num <= 1:

prev_page= '

else:

prev_page= '

self.params["page"] =i#如果等錢頁面等於選中的頁面 + class="active" 顯示顏色,否則的話就是正常顯示

if i ==self.current_page_num:

temp= '

%s' %(self.params.urlencode(), i)else:

temp= '

%s' %(self.params.urlencode(), i,)

if self.current_page_num >=self.all_pager:

next_page= '

else:

next_page= '

last_page= '

尾頁' %(self.all_pager,)

自定義分頁器

簡單直接,上 在專案的根目錄下新建乙個包 帶有 init py檔案的資料夾 或者直接將下面的pagenation包複製到你的專案中 新建乙個py檔案,如 pagenation.py 匯入元件 mark safe 自定義類 param request request物件 param all count...

自定義分頁器

class pagination object def init self,current page,all count,per page num 2,pager count 11 封裝分頁相關資料 param current page 當前頁 param all count 資料庫中的資料總條數 ...

自定義分頁

分頁 public string madebuttonlink int pagecount,int curpage,string szurl pagecount得到頁數 curpage當前頁 szurl連線位址 public int getpagecount string sztable,int l...