Skip to content

Commit 8a0502a

Browse files
authored
Merge pull request #6605 from WoltLab/62-grid-view-pagination-fix
Fix broken pagination in grid / list views when using filters
2 parents 039a4ec + cec5da6 commit 8a0502a

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,6 @@ protected function validate(): void
768768
if ($titleColumn === null) {
769769
throw new \InvalidArgumentException("Missing title column in grid view with id '{$this->getID()}'.");
770770
}
771-
772-
if ($this->getPageNo() > 1 && $this->getPageNo() > $this->countPages()) {
773-
$this->setPageNo($this->countPages() ?: 1);
774-
}
775771
}
776772

777773
/**
@@ -852,6 +848,19 @@ protected function initObjectList(): void
852848
$this->fireInitializedEvent();
853849
$this->validate();
854850

851+
if ($this->getObjectIDFilter() !== null) {
852+
$this->objectList->getConditionBuilder()->add(
853+
$this->objectList->getDatabaseTableAlias() . '.' . $this->objectList->getDatabaseTableIndexName() . ' = ?',
854+
[$this->getObjectIDFilter()]
855+
);
856+
}
857+
858+
$this->applyFilters();
859+
860+
if ($this->getPageNo() > 1 && $this->getPageNo() > $this->countPages()) {
861+
$this->setPageNo($this->countPages() ?: 1);
862+
}
863+
855864
$this->objectList->sqlLimit = $this->getRowsPerPage();
856865
$this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getRowsPerPage();
857866
if ($this->getSortField()) {
@@ -866,14 +875,6 @@ protected function initObjectList(): void
866875
$this->objectList->sqlOrderBy .= ',' . $this->objectList->getDatabaseTableAlias() .
867876
'.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder();
868877
}
869-
if ($this->getObjectIDFilter() !== null) {
870-
$this->objectList->getConditionBuilder()->add(
871-
$this->objectList->getDatabaseTableAlias() . '.' . $this->objectList->getDatabaseTableIndexName() . ' = ?',
872-
[$this->getObjectIDFilter()]
873-
);
874-
}
875-
876-
$this->applyFilters();
877878
}
878879

879880
/**

wcfsetup/install/files/lib/system/listView/AbstractListView.class.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ protected function initObjectList(): void
246246
$this->fireInitializedEvent();
247247
$this->validate();
248248

249-
$this->objectList->sqlLimit = $this->getFixedNumberOfItems() ?: $this->getItemsPerPage();
250-
if (!$this->getFixedNumberOfItems()) {
251-
$this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getItemsPerPage();
252-
}
253-
$this->objectList->sqlOrderBy = $this->getSqlOrderBy();
254249
if ($this->getObjectIDFilter() !== null) {
255250
$this->objectList->getConditionBuilder()->add(
256251
$this->objectList->getDatabaseTableAlias() . '.' . $this->objectList->getDatabaseTableIndexName() . ' = ?',
@@ -259,6 +254,16 @@ protected function initObjectList(): void
259254
}
260255

261256
$this->applyFilters();
257+
258+
if ($this->getPageNo() > 1 && $this->getPageNo() > $this->countPages()) {
259+
$this->setPageNo($this->countPages() ?: 1);
260+
}
261+
262+
$this->objectList->sqlLimit = $this->getFixedNumberOfItems() ?: $this->getItemsPerPage();
263+
if (!$this->getFixedNumberOfItems()) {
264+
$this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getItemsPerPage();
265+
}
266+
$this->objectList->sqlOrderBy = $this->getSqlOrderBy();
262267
}
263268

264269
protected function validate(): void
@@ -276,10 +281,6 @@ protected function validate(): void
276281
}
277282
}
278283
}
279-
280-
if ($this->getPageNo() > 1 && $this->getPageNo() > $this->countPages()) {
281-
$this->setPageNo($this->countPages() ?: 1);
282-
}
283284
}
284285

285286
protected function getSqlOrderBy(): string

0 commit comments

Comments
 (0)