kartik-v / yii2-grid

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

GridView::ROW_EXPANDED doesn't work #947

Closed pappfer closed 4 years ago

pappfer commented 4 years ago

Prerequisites

This bug is similar to https://github.com/kartik-v/yii2-grid/issues/586 what I fixed earlier. I have this setting:

'value' => function ($model, $key, $index, $column) {
    if (Yii::$app->request->get('id') == $key) {
        return kartik\grid\GridView::ROW_EXPANDED;
    } else {
        return kartik\grid\GridView::ROW_COLLAPSED;
    }
},

Even thought the id parameter is passed, the row won't open. The problem is caused by line 228-230 in kv-grid-expand.js:

if (isExpanded($icon)) {
    return;
}

It occurs because isExpanded will be true when GridView::ROW_EXPANDED is set, so it ignores the rest of the javascript code and won't open the row. I currently don't have the chance to check why those lines are present so I can't create a pull request at the moment.

kartik-v commented 4 years ago

Thanks - the row expansion on INIT was intended to work by default with plain CSS (so no JS was needed to parse) - but if you are using ajax based rendering option for expanded detail (instead of normal render) it may not work. Will need to check this.

pappfer commented 4 years ago

Yes, I'm using ajax based rendering.

kartik-v commented 4 years ago

This has been resolved with the latest commit (also has a related enhancement #948).

pappfer commented 4 years ago

@kartik-v Sorry, but doesn't seem to work. It is complaining about an undefined variable at line 192. TypeError: $detail.html(...) is undefined

kartik-v commented 4 years ago

@pappfer - I am not able to reproduce your issue - hope you have the latest assets loaded?

How are you configuring your ExpandRowColumn (are you using nested GridViews)?

kartik-v commented 4 years ago

I pushed in a commit. Can you retry and let know?

pappfer commented 4 years ago

I don't get the console error now, but the row doesn't get expanded. I am not using nested GridViews. I am using a configuration mentioned in the first post along with 'detailUrl'.

kartik-v commented 4 years ago

I am unable to reproduce your issue. Currently to show this works fine - there is a new ExpandRowColumn demo enabled on the demos page. Refer the new expand row column demo. You can cross check the grid columns configuration by clicking the Grid Columns Setup button.

This has similar configuration with detailUrl to render via ajax and selective rows expanded on INIT (in the example demo even numbered rows are configured to be expanded on init).

Let me know if you have something else on your environment or configuration which is missed.

pappfer commented 4 years ago

It is really weird, because in my project sometimes it works, sometimes it doesn't. Sure, I am using the latest version and having the cache and the web/assets folder cleared. Unfortunately I don't have time to debug it now, for now I am using version 3.3.4 in my Composer and it works fine with that. When I'll get a little time, I'll investigate the issue.

cebe commented 4 years ago

@kartik-v I'm having the same issue, not sure about the cause but I think this should be reopened. I'll try to figure out more details about this tomorrow.

hoaaah commented 4 years ago

Got this issue too, but after clean my assets folder, it works again.

cebe commented 4 years ago

In our case it was conflicting with custom JS code of the project.