Skip to content

Commit

Permalink
Merge branch 'master' into 218-ability-to-set-page-size
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Nov 16, 2024
2 parents 14b35ee + b5108c4 commit 372c1d4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/BasePagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ final public function render(): string
$html .= Html::openTag($this->itemTag, $attributes);
}

$attributes = $this->linkAttributes;
$linkAttributes = $this->linkAttributes;
if ($item->isDisabled) {
Html::addCssClass($attributes, $this->disabledLinkClass);
Html::addCssClass($linkAttributes, $this->disabledLinkClass);
}
if ($item->isCurrent) {
Html::addCssClass($attributes, $this->currentLinkClass);
Html::addCssClass($linkAttributes, $this->currentLinkClass);
}
$html .= Html::a($item->label, $item->url, $attributes);
$html .= Html::a($item->label, $item->url, $linkAttributes);

if ($this->itemTag !== null) {
$html .= Html::closeTag($this->itemTag);
Expand Down Expand Up @@ -260,7 +260,7 @@ protected function createUrl(PageToken $pageToken, ?int $pageSize = null): strin

$paginator = $this->getPaginator();
$pageSize ??= $paginator->getPageSize();
$sort = $paginator->getSort()?->getOrderAsString();
$sort = $paginator->isSortable() ? $paginator->getSort()?->getOrderAsString() : null;

return call_user_func_array(
$this->urlCreator,
Expand Down
32 changes: 32 additions & 0 deletions tests/GridView/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
use Yiisoft\Yii\DataView\GridView;
use Yiisoft\Yii\DataView\Tests\Support\Assert;
use Yiisoft\Yii\DataView\Tests\Support\TestTrait;
use Yiisoft\Data\Paginator\OffsetPaginator;
use Yiisoft\Data\Reader\Iterable\IterableDataReader;
use Yiisoft\Data\Reader\Sort;
use Yiisoft\Yii\DataView\Tests\Support\SimplePaginationUrlCreator;

final class BaseTest extends TestCase
{
Expand Down Expand Up @@ -675,4 +679,32 @@ public function testTableAttributes(): void
->render()
);
}

public function testNoSortInUrlWhenLimited(): void
{
$sort = Sort::any()->withOrder(['id' => 'asc', 'name' => 'asc']);
$data = (new IterableDataReader($this->data))
->withSort($sort)
->withLimit(10);

$paginator = (new OffsetPaginator($data))
->withPageSize(1);

$output = GridView::widget()
->columns(
new SerialColumn(),
new DataColumn('id'),
new DataColumn('name'),
new DataColumn('age'),
)
->id('w1-grid')
->dataReader($paginator)
->offsetPaginationConfig([
'urlCreator()' => [new SimplePaginationUrlCreator()],
])
->tableAttributes(['class' => 'table table-striped table-bordered'])
->render();

$this->assertStringNotContainsString('sort=', $output);
}
}

0 comments on commit 372c1d4

Please sign in to comment.