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

[Feature] Option to have an ExpandRowColumn row always remain open until it is manually closed #912

Closed
7 of 9 tasks
adamwinn opened this issue Jun 12, 2019 · 10 comments
Closed
7 of 9 tasks

Comments

@adamwinn
Copy link

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-grid.
  • This is not an usage question. I confirm having gone through and read the documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

We would like a row that is expanded to always remain open even after a page refresh or a pjax pagination change, etc.

An example of this on the demo page would be to have the Grapes of Wrath row remain expanded after clicking to go to page 2 and then clicking to go back to page 1.

Another example would be if the Grapes of Wrath row were expanded and and the Add to Cart button was pressed and then the user checked out and was redirected back to the demo page, that row would still be expanded.

Or an option to open a row via javascript would also help. I can keep track of which row was opened and then upon page refresh, call some function like kv_ExpandRow('2') and it will expand row 2 upon page load.

  • This bug happens on the demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-grid without other plugins.
@kartik-v
Copy link
Owner

kartik-v commented Jun 18, 2019

This feature is already available via value setting for the ExpandRowColumn.

You should be able to set the value for the expand row column cell using Closure method to GridView::ROW_EXPANDED for those rows which you wish to stay expanded. Implement a similar model level indicator which will help you track this for your use case.

For example:

[
    'class' => 'kartik\grid\ExpandRowColumn',
    'width' => '50px',
    'value' => function ($model, $key, $index, $column) {
        if ($model->status === 'FEATURED') { // keep it expanded for specific rows
            return GridView::ROW_EXPANDED;
        }
        return GridView::ROW_COLLAPSED;
    },
    'detail' => function ($model, $key, $index, $column) {
        return Yii::$app->controller->renderPartial('_expand-row-details', ['model' => $model]);
    },
    'headerOptions' => ['class' => 'kartik-sheet-style'] 
],

@adamwinn
Copy link
Author

The problem is I need to have all rows collapsed by default, then the user will randomly open any rows and those rows should remain open. Your example won't work since it only works for a use case where a row is "featured".

So the user goes to the page, randomly opens any row (lets say row 5 that is no different than the rest of the rows), then goes to page 2 via pjax, then back to page 1 via pjax. Row 5 should remain open.

@kartik-v
Copy link
Owner

That was just an example. It is an application level design and programming you need to do for your use case. You need to store the expanded states for the user in a table/storage and use this to set the column value via Closure method.

@kenjisoul
Copy link

@kartik-v I had set return GridView::ROW_EXPANDED; it's just loading and stop but row not expand???

This is my code:

[
    'class' => 'kartik\grid\ExpandRowColumn',
    'width' => '50px',
    'value' => function ($model, $key, $index, $column) {
        if ($model->id == 46) {        
            return GridView::ROW_EXPANDED;
        } else {
            return GridView::ROW_COLLAPSED;
        }
    },
    'detail' => function ($model, $key, $index, $column) {
        return Yii::$app->controller->renderPartial('view', ['model' => $model]);
    },
    'headerOptions' => ['class' => 'kartik-sheet-style'],
    'expandOneOnly' => true
],
`

@lucsvasconcelos
Copy link

@kartik-v I had set return GridView::ROW_EXPANDED; it's just loading and stop but row not expand???

This is my code:

[
    'class' => 'kartik\grid\ExpandRowColumn',
    'width' => '50px',
    'value' => function ($model, $key, $index, $column) {
        if ($model->id == 46) {        
            return GridView::ROW_EXPANDED;
        } else {
            return GridView::ROW_COLLAPSED;
        }
    },
    'detail' => function ($model, $key, $index, $column) {
        return Yii::$app->controller->renderPartial('view', ['model' => $model]);
    },
    'headerOptions' => ['class' => 'kartik-sheet-style'],
    'expandOneOnly' => true
],
`

I got this issue too, since grid updated from 3.3.4 to 3.3.5, defaultHeader and value as ROW_EXPANDED not working anymore.

@jstudioo
Copy link

@kartik-v I had set return GridView::ROW_EXPANDED; it's just loading and stop but row not expand???

This is my code:

[
    'class' => 'kartik\grid\ExpandRowColumn',
    'width' => '50px',
    'value' => function ($model, $key, $index, $column) {    
            return GridView::ROW_EXPANDED;
    },
    ........
],
`

I got this issue too. just loading and stop but row not expand

@mtkumar82
Copy link

I am facing the same issue, Any solution for this?

@IlyasArinov
Copy link

Just encountered similar issue I think - value not working. Downgrading helped.

@synatree
Copy link

Can confirm that this is a real issue, and it was corrected by downgrading to 3.3.4.

@stale
Copy link

stale bot commented Oct 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants