Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionColumn buttons (by default) reset filters #15

Open
vologab opened this issue Apr 9, 2016 · 10 comments
Open

ActionColumn buttons (by default) reset filters #15

vologab opened this issue Apr 9, 2016 · 10 comments
Assignees
Labels
help wanted Extra attention is needed status:ready for adoption Feel free to implement this issue. type:test Test

Comments

@vologab
Copy link

vologab commented Apr 9, 2016

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
@samdark samdark transferred this issue from yiisoft/yii2 Apr 23, 2019
@samdark
Copy link
Member

samdark commented Apr 23, 2019

yiisoft/yii2#11320

@samdark
Copy link
Member

samdark commented Sep 27, 2024

Need a test that verifies such behavior i.e. sorting and filtering is taken into account when generating URL for an action button.

@samdark samdark added help wanted Extra attention is needed status:ready for adoption Feel free to implement this issue. type:test Test labels Sep 27, 2024
@samdark samdark added this to the 1.0 milestone Sep 27, 2024
@glpzzz
Copy link
Contributor

glpzzz commented Oct 13, 2024

4. As result - all filters reseted

I'm not clear on this part. As a result the action is performed (navigate to view/edit/delete). And it's depending on the action which page is rendered next.

Assuming the default markup for a Gii CRUD generated page:

I understand that the current parameters could be passed (to the delete button for example) to allow redirect to the index page and end up on the same view (page X, filtered by field Y and sorted by field Z) as before of clicking the delete button... but I think it's an specific behavior that the developer should be able to choose to use or not.

This behavior could be added as an option:

  • boolean $includeRequestParams,
  • or boolean|array $requestParamsToInclude (boolean to pass all of them)

at ActionColumn level or at button level (my personal preference).

@vjik
Copy link
Member

vjik commented Oct 18, 2024

Currently URL for action buttons don't generate automatically.

Is such generation necessary? If yes, by what logic should it work?

@samdark
Copy link
Member

samdark commented Oct 19, 2024

It's about redirect that happens after an action is done, i.e. returning to the same filtered view after deletion is done or editing is done.

  1. Go to page 5, filtered by username = X.
  2. Delete a user.
  3. Redirect to page 5, filtered by username = X happens.

There are edge cases, though, such as deleting a record so the page no longer exists.

@samdark samdark removed this from the 1.0 milestone Oct 19, 2024
@samdark
Copy link
Member

samdark commented Oct 19, 2024

I think it can safely be done after initial release.

@vjik
Copy link
Member

vjik commented Oct 19, 2024

It can be done something like this.

  1. Optionally, add encoded current parameters to URL in actions as separate parameter.
  2. Create new class for generate URL to page with GridView, that use encoded paramater from step 1.

@glpzzz
Copy link
Contributor

glpzzz commented Oct 21, 2024

I think I can do this task.

@samdark
Copy link
Member

samdark commented Nov 12, 2024

@glpzzz any luck with it?

@glpzzz
Copy link
Contributor

glpzzz commented Nov 23, 2024

Not yet. WIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed status:ready for adoption Feel free to implement this issue. type:test Test
Projects
None yet
Development

No branches or pull requests

4 participants