Fix pagination reset if search input is filled (#4918)

Fixes #4914.
This commit is contained in:
Samuell 2020-02-12 16:52:09 +01:00 committed by GitHub
parent 495b0f085a
commit a68f3abf1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 7 deletions

View File

@ -212,7 +212,7 @@ class ListController extends ControllerBehavior
*/
if ($searchWidget = $toolbarWidget->getSearchWidget()) {
$searchWidget->bindEvent('search.submit', function () use ($widget, $searchWidget) {
$widget->setSearchTerm($searchWidget->getActiveTerm());
$widget->setSearchTerm($searchWidget->getActiveTerm(), true);
return $widget->onRefresh();
});

View File

@ -642,9 +642,7 @@ class Lists extends WidgetBase
protected function getCurrentPageNumber($query)
{
$currentPageNumber = $this->currentPageNumber;
if (!$currentPageNumber && empty($this->searchTerm)) {
// Restore the last visited page from the session if available.
if (empty($currentPageNumber)) {
$currentPageNumber = $this->getSession('lastVisitedPage');
}
@ -1410,13 +1408,18 @@ class Lists extends WidgetBase
* Applies a search term to the list results, searching will disable tree
* view if a value is supplied.
* @param string $term
* @param boolean $resetPagination
*/
public function setSearchTerm($term)
public function setSearchTerm($term, $resetPagination = false)
{
if (!empty($term)) {
$this->showTree = false;
}
if ($resetPagination) {
$this->currentPageNumber = 1;
}
$this->searchTerm = $term;
}

View File

@ -34,7 +34,8 @@
name="page"
class="form-control input-sm custom-select select-no-search"
data-request="<?= $this->getEventHandler('onPaginate') ?>"
data-load-indicator="<?= e(trans('backend::lang.list.loading')) ?>">
data-load-indicator="<?= e(trans('backend::lang.list.loading')) ?>"
autocomplete="off">
<?php for($i = 1; $i <= $pageLast ; $i++): ?>
<option value="<?= $i ?>" <?= $i === $pageCurrent ? 'selected' : '' ?>><?= $i ?></option>
<?php endfor ?>

View File

@ -29,7 +29,8 @@
<select
disabled
name="page"
class="form-control input-sm custom-select select-no-search">
class="form-control input-sm custom-select select-no-search"
autocomplete="off">
<option value="<?= $pageCurrent ?>" selected><?= $pageCurrent ?></option>
</select>
<?php if ($hasMorePages): ?>