Dynamically using GridView using Ajax

Hello All,

I am trying to implement a nested GridView using Expand Row Column.

A main-grid is displayed, generally showing totals, of which each column can be expanded loading a sub-grid, displaying the data sources on which the totals are based.

This issue is very similar to the following issues:


https://github.com/kartik-v/yii2-grid/issues/324 and https://github.com/kartik-v/yii2-grid/issues/348

Using the component, data can be loaded directly using the ‘detail’ option.


'detail' => function ($model, $key, $index, $column) {

              $searchModel = new \app\models\search\Subject;

              $searchModel->bySector = $key;

              $dataProvider = $searchModel->search($this->getSubGridFilter());

              return Yii::$app->controller->renderPartial('/linkage/_subgrid', [

                'searchModel' => $searchModel,

                'dataProvider' => $dataProvider,

                'gridId' => $key,



The solution is functional, only that performance is quite bad, as a subgrid is rendered for each column when loading the page.

Using the detailUrl option, ajax is used to load the subgrid. The initial page load is quite much faster, as each subgrid is loaded when required.

The component calls the controller action

   'detailUrl' => Yii::$app->urlManager->createUrl(['/' . Yii::$app->controller->id . '/sector-details', 'filter' => $this->getSubgridFilter()]),

In the controller

    public function actionLocationDetails(array $filter = [])


        if (isset($_POST['expandRowKey'])) {

            $countryId = $_POST['expandRowKey'];

            $searchModel = $this->_initSearch();

            $searchModel->byCountry = $countryId;

            $dataProvider = $searchModel->search($filter);

            return $this->renderPartial('/linkage/_subgrid', [

                        'searchModel' => $searchModel,

                        'dataProvider' => $dataProvider,

                        'gridId' => $countryId,


        } else {

            return '<div class="alert alert-danger">No data found</div>';



Sorting and pagination on the subgrid however fails. I believe this has to do with the fact that calling the call to renderPartial does not publish the javascript required to have a GridView properly functioning.

I have tried to replace renderPartial with renderAjax, but this does not resolve anything.

How can I get Yii to publish the javascript?