Skip to content

Commit 1f9ed70

Browse files
author
gustavnavar
committed
Fix change of page size
1 parent c496302 commit 1f9ed70

4 files changed

Lines changed: 50 additions & 49 deletions

File tree

gridcore/src/main/java/me/agno/gridcore/Grid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ protected void prepareItemsToDisplay() {
259259
this.orderList = this.sortProcessor.process(this.orderList);
260260
if(this.orderList != null && ! this.orderList.isEmpty())
261261
this.criteriaQuery.orderBy(this.orderList);
262-
this.itemsToList = this.pagerProcessor.process(this.criteriaQuery).getResultList();
262+
this.itemsToList = ((PagerProcessor<T>)this.pagerProcessor).process(this.criteriaQuery, getItemsCount()).getResultList();
263263
}
264264
}
265265

gridcore/src/main/java/me/agno/gridcore/pagination/GridPager.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,65 @@ public class GridPager<T> implements IGridPager<T> {
1717
public final static String DEFAULT_VIRTUALIZED_COUNT_QUERY_PARAMETER = "grid-virt-count";
1818
public final static String DEFAULT_NO_TOTALS_PARAMETER = "grid-no-totals";
1919

20+
private final CustomQueryStringBuilder queryBuilder;
21+
22+
2023
@Getter
2124
private final IGrid<T> grid;
2225

23-
private final CustomQueryStringBuilder queryBuilder;
24-
2526
private int currentPage;
2627

28+
public int getCurrentPage() {
29+
30+
if (this.currentPage >= 0 || this.grid.getPagingType() == PagingType.VIRTUALIZATION) return this.currentPage;
31+
var currentPageParameter = this.grid.getQuery().get(this.parameterName);
32+
if(currentPageParameter != null && currentPageParameter.size() == 1)
33+
this.currentPage = Integer.parseInt(currentPageParameter.get(0));
34+
else
35+
this.currentPage = 1;
36+
37+
if (this.currentPage > this.pageCount)
38+
this.currentPage = this.pageCount;
39+
return this.currentPage;
40+
}
41+
42+
public void setCurrentPage(int value) {
43+
this.currentPage = value;
44+
RecalculatePages();
45+
}
46+
2747
@Getter
28-
private int itemsCount;
48+
private long itemsCount;
49+
50+
public void setItemsCount(long value) {
51+
this.itemsCount = value;
52+
RecalculatePages();
53+
}
2954

3055
@Getter
3156
private int maxDisplayedPages = DEFAULT_MAX_DISPLAYED_PAGES;
3257

58+
public void setMaxDisplayedPages(int value) {
59+
this.maxDisplayedPages = value;
60+
RecalculatePages();
61+
}
62+
3363
@Getter
3464
private int pageSize;
3565

66+
public void setPageSize(int value) {
67+
this.pageSize = value;
68+
RecalculatePages();
69+
}
70+
3671
@Getter
3772
private int queryPageSize;
3873

74+
public void setQueryPageSize(int value) {
75+
this.queryPageSize = value;
76+
RecalculatePages();
77+
}
78+
3979
@Getter
4080
@Setter
4181
private int startIndex = 0;
@@ -99,47 +139,8 @@ public GridPager(IGrid<T> grid) {
99139
}
100140
}
101141

102-
public void initialize(int count) {
103-
this.itemsCount = count;
104-
}
105-
106-
public void setPageSize(int value) {
107-
this.pageSize = value;
108-
RecalculatePages();
109-
}
110-
111-
public void setQueryPageSize(int value) {
112-
this.queryPageSize = value;
113-
RecalculatePages();
114-
}
115-
116-
public int getCurrentPage() {
117-
118-
if (this.currentPage >= 0 || this.grid.getPagingType() == PagingType.VIRTUALIZATION) return this.currentPage;
119-
var currentPageParameter = this.grid.getQuery().get(this.parameterName);
120-
if(currentPageParameter != null && currentPageParameter.size() == 1)
121-
this.currentPage = Integer.parseInt(currentPageParameter.get(0));
122-
else
123-
this.currentPage = 1;
124-
125-
if (this.currentPage > this.pageCount)
126-
this.currentPage = this.pageCount;
127-
return this.currentPage;
128-
}
129-
130-
public void setCurrentPage(int value) {
131-
this.currentPage = value;
132-
RecalculatePages();
133-
}
134-
135-
public void setItemsCount(int value) {
136-
this.itemsCount = value;
137-
RecalculatePages();
138-
}
139-
140-
public void setMaxDisplayedPages(int value) {
141-
this.maxDisplayedPages = value;
142-
RecalculatePages();
142+
public void initialize(long count) {
143+
setItemsCount(count);
143144
}
144145

145146
protected void RecalculatePages() {

gridcore/src/main/java/me/agno/gridcore/pagination/IGridPager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public interface IGridPager<T> {
66

77
IGrid<T> getGrid();
88

9-
void initialize(int count);
9+
void initialize(long count);
1010

1111
int getPageSize();
1212

@@ -18,9 +18,9 @@ public interface IGridPager<T> {
1818

1919
int getCurrentPage();
2020

21-
int getItemsCount();
21+
long getItemsCount();
2222

23-
void setItemsCount(int itemsCount);
23+
void setItemsCount(long itemsCount);
2424

2525
int getStartIndex();
2626

gridcore/src/main/java/me/agno/gridcore/pagination/PagerProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public PagerProcessor(IGrid<T> grid) {
1717
this.grid = grid;
1818
}
1919

20-
public TypedQuery<T> process(CriteriaQuery<T> items, int count) {
20+
public TypedQuery<T> process(CriteriaQuery<T> items, long count) {
2121
this.grid.getPager().initialize(count);
2222
return process(items);
2323
}

0 commit comments

Comments
 (0)