kartik-v / yii2-grid

Enhanced GridView with various utilities for Yii Framework 2.0
http://demos.krajee.com/grid
Other
556 stars 302 forks source link

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

Closed adamwinn closed 2 years ago

adamwinn commented 5 years ago

Prerequisites

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.

kartik-v commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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

IlyasArinov commented 3 years ago

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

synatree commented 3 years ago

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

stale[bot] commented 3 years ago

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.