Skip to content

ActionColumn buttons (by default) reset filters #15

@vologab

Description

@vologab

What steps will reproduce the problem?

  1. Create GridView with ActionColumn and filters/sorting features.
  2. Select some filters and sort some columns
  3. Click button in ActionColumn
  4. As result - all filters reseted

What is the expected result?

Filters/Sorters should be saved/restored after clicking buttons in action column.

What do you get instead?

All filters reseted, after clicking actionColumn button.

As temporary solution, it's possible use closure in action column

[
'class' => '\yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {

 $request = \Yii::$app->getRequest();
 $paramsFromRequest = $request instanceof \yii\web\Request ? $request->getQueryParams() : [];

$params = is_array($key) ? $key : ['id' => (string) $key];
$params[0] = \Yii::$app->controller->id . '/' . $action;

return \Yii::$app->urlManager->createUrl(array_merge($paramsFromRequest, $params));
]

Additional info

Method createUrl() also used in Pagination.php, Sort.php, but in these classes for creating Url is used current parameters from request, so we don't have problems with resetting filters/sorting.

But for action column we should use slightly different solution because, creteUrl will be executed for each row/column, so we need params 'caching' (may be in GridView widget) from request for avoiding $paramsFromRequest = $request instanceof \yii\web\Request ? $request->getQueryParams() : []; calculating in each row.

Q A
Yii version 2.0.7-372-g5921865
PHP version PHP 5.6.11
Operating system Ubuntu

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions