Skip to content

Commit

Permalink
Merge branch 'hotfix/4.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pfilsx committed Nov 16, 2019
2 parents 9d32503 + 1801862 commit d4e15cc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/Config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class Configuration implements ConfigurationInterface

protected $paginationEnabled;

protected $showTitles;

protected $translationDomain;

public function __construct(array $config = [])
Expand Down
1 change: 1 addition & 0 deletions src/Grid/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ protected function handleSorting(array &$queryParams)
$this->setSort($queryParams['sortBy']);
unset($queryParams['sortBy']);
}
$this->builder->acquireSort();
}

protected function handlePagination(array &$queryParams)
Expand Down
31 changes: 26 additions & 5 deletions src/Grid/DataGridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class DataGridBuilder implements DataGridBuilderInterface

protected $instance = 'default';

protected $sort = null;

/**
* DataGridBuilder constructor.
* @param DataGridServiceContainer $container
Expand Down Expand Up @@ -161,17 +163,36 @@ public function setProvider(DataProviderInterface $provider): void
$this->provider = $provider;
}

/**
* @param string $attribute
* @param string $direction
*/
public function setSort(string $attribute, string $direction)
{
foreach ($this->columns as $column) {
if ($column instanceof DataColumn && $column->hasSort() && $column->getAttribute() == $attribute) {
$column->setSort($direction);
$this->provider->setSort([$attribute => $direction]);
break;
$this->sort = [$attribute, $direction];
}

/**
* @internal
*/
public function acquireSort(): void
{
if (is_array($this->sort) && count($this->sort) === 2) {
$attribute = $this->sort[0];
$direction = $this->sort[1];
foreach ($this->columns as $column) {
if ($column instanceof DataColumn && $column->hasSort() && $column->getAttribute() == $attribute) {
$column->setSort($direction);
$this->provider->setSort([$attribute => $direction]);
break;
}
}
}
}




/**
* @internal
* @return bool
Expand Down
6 changes: 5 additions & 1 deletion src/Grid/DataGridBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public function getInstance(): string;
/**
* @param string $attribute
* @param string $direction
* @internal
*/
public function setSort(string $attribute, string $direction);

/**
* @internal
*/
public function acquireSort(): void;
}
8 changes: 4 additions & 4 deletions src/Resources/views/grid.blocks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
{% else %}
{% set sort_attribute = {'sortBy': column.attribute} %}
{% endif %}
<a href="{{ path(request.get('_route'),
request.query|merge({'data_grid': request.query.get('data_grid')|default({})|merge(sort_attribute)})) }}"
<a href="{{ path(request.attributes.get('_route'),
(request.attributes.get('_route_params')|merge(request.query))|merge({'data_grid': request.query.get('data_grid')|default({})|merge(sort_attribute)})) }}"
class="data_grid_sort{% if column.getSort is same as('ASC') %} up{% elseif column.getSort is same as('DESC') %} down{% endif %}"
data-attribute="{{ column.attribute }}">{{ column.headContent }}</a>
{% else %}
Expand Down Expand Up @@ -79,8 +79,8 @@
{% elseif i is same as(null) %}
...
{% else %}
<a href="{{ path(request.get('_route'),
request.query|merge({'data_grid': request.query.get('data_grid')|default({})|merge({'page': i})})) }}"
<a href="{{ path(request.attributes.get('_route'),
(request.attributes.get('_route_params')|merge(request.query))|merge({'data_grid': request.query.get('data_grid')|default({})|merge({'page': i})})) }}"
class="data_grid_page" data-page="{{ i }}">{{ i }}</a>
{% endif %}
{% endfor %}
Expand Down
1 change: 1 addition & 0 deletions tests/DataGridBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function testSetPagination(): void
public function testSetSort($builder): void
{
$builder->setSort('creationDate', 'DESC');
$builder->acquireSort();
foreach ($builder->getColumns() as $column) {
/**
* @var $column AbstractColumn
Expand Down

0 comments on commit d4e15cc

Please sign in to comment.