{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9040","repository_url":"https://api.github.com/repos/yiisoft/yii2","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9040/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9040/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9040/events","html_url":"https://github.com/yiisoft/yii2/issues/9040","id":93683226,"number":9040,"title":"Refreshing Listview inside modal dialog using Pjax","user":{"login":"re1naldo","id":5090929,"avatar_url":"https://avatars.githubusercontent.com/u/5090929?v=3","gravatar_id":"","url":"https://api.github.com/users/re1naldo","html_url":"https://github.com/re1naldo","followers_url":"https://api.github.com/users/re1naldo/followers","following_url":"https://api.github.com/users/re1naldo/following{/other_user}","gists_url":"https://api.github.com/users/re1naldo/gists{/gist_id}","starred_url":"https://api.github.com/users/re1naldo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/re1naldo/subscriptions","organizations_url":"https://api.github.com/users/re1naldo/orgs","repos_url":"https://api.github.com/users/re1naldo/repos","events_url":"https://api.github.com/users/re1naldo/events{/privacy}","received_events_url":"https://api.github.com/users/re1naldo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/feature:pjax","name":"feature:pjax","color":"c7def8"},{"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:to%20be%20verified","name":"status:to be verified","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"SilverFire","id":4499203,"avatar_url":"https://avatars.githubusercontent.com/u/4499203?v=3","gravatar_id":"","url":"https://api.github.com/users/SilverFire","html_url":"https://github.com/SilverFire","followers_url":"https://api.github.com/users/SilverFire/followers","following_url":"https://api.github.com/users/SilverFire/following{/other_user}","gists_url":"https://api.github.com/users/SilverFire/gists{/gist_id}","starred_url":"https://api.github.com/users/SilverFire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SilverFire/subscriptions","organizations_url":"https://api.github.com/users/SilverFire/orgs","repos_url":"https://api.github.com/users/SilverFire/repos","events_url":"https://api.github.com/users/SilverFire/events{/privacy}","received_events_url":"https://api.github.com/users/SilverFire/received_events","type":"User","site_admin":false},"assignees":[{"login":"SilverFire","id":4499203,"avatar_url":"https://avatars.githubusercontent.com/u/4499203?v=3","gravatar_id":"","url":"https://api.github.com/users/SilverFire","html_url":"https://github.com/SilverFire","followers_url":"https://api.github.com/users/SilverFire/followers","following_url":"https://api.github.com/users/SilverFire/following{/other_user}","gists_url":"https://api.github.com/users/SilverFire/gists{/gist_id}","starred_url":"https://api.github.com/users/SilverFire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SilverFire/subscriptions","organizations_url":"https://api.github.com/users/SilverFire/orgs","repos_url":"https://api.github.com/users/SilverFire/repos","events_url":"https://api.github.com/users/SilverFire/events{/privacy}","received_events_url":"https://api.github.com/users/SilverFire/received_events","type":"User","site_admin":false}],"milestone":null,"comments":16,"created_at":"2015-07-08T03:35:07Z","updated_at":"2016-07-17T00:01:46Z","closed_at":null,"body":"I have a Listview that is rendered inside a modal dialog:\r\n```\r\n<?php Pjax::begin([\r\n    'id' => 'image-list',\r\n    'timeout' => Yii::$app->params['timeout'], \r\n    'enablePushState' => false        \r\n]); ?>\r\n               \r\n        <?= ListView::widget([\r\n            'dataProvider' => $dataProvider,          \r\n            'options' => ['class' => 'list-view'],          \r\n            'itemView' => function ($model, $key, $index, $widget) {\r\n                $path = $model->getImage();\r\n                $size = $model->getImageSize(100, 'H');\r\n                \r\n                return Html::a(Html::img($path, [\r\n                        'width' => $size['width'],\r\n                        'height' => $size['height'],\r\n                    ]), $path).\r\n                    Html::a('<i class=\"glyphicon glyphicon-trash\"></i>', '#', [\r\n                        'class' => 'arr-img pull-left',\r\n                        'title' => 'Delete',\r\n                        'onclick' => \"\r\n                            if (confirm('Are you sure you want to delete this image?') == true) {                            \r\n                                $.ajax({            \r\n                                    type: 'POST',\r\n                                    cache: false,\r\n                                    url: '\" .Yii::$app->urlManager->createUrl(['arrangement-image/delete', 'id' => $model->id]). \"',\r\n                                    success: function(response) {\r\n                                        $.pjax.reload({container: '#image-list', timeout: \" .Yii::$app->params['timeout']. \"});\r\n                                    }\r\n                                });\r\n                            }\r\n                            \r\n                            return false;\r\n                        \"\r\n                    ]);\r\n            },\r\n        ]) ?>\r\n    \r\n<?php Pjax::end(); ?>\r\n```\r\n\r\nThat Listview is rendered via ajax request:\r\n```\r\n'image' => function ($url, $model) {\r\n    return Html::a('<i class=\"glyphicon glyphicon-picture\"></i>', '#', [\r\n         'title' => 'View Images',\r\n          'onclick' => \"\r\n               $('#image-modal').modal('show');\r\n\r\n               $.ajax({            \r\n                  type: 'POST',\r\n                  cache: false,\r\n                  url: '\" .Yii::$app->urlManager->createUrl(['arrangement-image/index', 'id' => $model->id]). \"',\r\n                  success: function(response) {\r\n                        $('#image-modal .modal-body').html(response);\r\n                  },\r\n              });\r\n\r\n              return false;\r\n       \",\r\n  ]);                            \r\n}\r\n```\r\n\r\nThe data loading and pagination work fine, but when I tried to refresh Listview using `$.pjax.reload`, the whole page was refreshed and modal dialog was closed. This doesn't happen when I render the Listview without modal dialog.\r\n\r\nThere are other people ([Thread 1](http://stackoverflow.com/questions/28674432/how-to-update-widget-with-pjax-in-modal-window-in-yii2), [Thread 2](http://www.yiiframework.com/forum/index.php/topic/56040-pjaxreload-with-post-url/)) who have ever posted about this topic. Unfortunately, there is not a specific solution for this as far as I can see. How to refresh Listview inside modal without refreshing the whole page?"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/233157516","html_url":"https://github.com/yiisoft/yii2/issues/9040#issuecomment-233157516","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/9040","id":233157516,"user":{"login":"tunecino","id":5133397,"avatar_url":"https://avatars.githubusercontent.com/u/5133397?v=3","gravatar_id":"","url":"https://api.github.com/users/tunecino","html_url":"https://github.com/tunecino","followers_url":"https://api.github.com/users/tunecino/followers","following_url":"https://api.github.com/users/tunecino/following{/other_user}","gists_url":"https://api.github.com/users/tunecino/gists{/gist_id}","starred_url":"https://api.github.com/users/tunecino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tunecino/subscriptions","organizations_url":"https://api.github.com/users/tunecino/orgs","repos_url":"https://api.github.com/users/tunecino/repos","events_url":"https://api.github.com/users/tunecino/events{/privacy}","received_events_url":"https://api.github.com/users/tunecino/received_events","type":"User","site_admin":false},"created_at":"2016-07-17T00:01:46Z","updated_at":"2016-07-17T00:01:46Z","body":"here is a minimal example to reproduce it in a view file:\r\n\r\n```php\r\n<?php\r\nuse yii\\widgets\\Pjax;\r\nuse yii\\grid\\GridView;\r\nuse yii\\data\\ArrayDataProvider;\r\n\r\nsleep(1); /* this will trigger the timeout error with whatever value set via php*/\r\n?>\r\n\r\n<button onclick=\"$.pjax.reload({container:'#pjax'});\">reload pjax</button>\r\n<pre id=\"output\"></pre>\r\n\r\n<?php Pjax::begin(['id'=>'pjax', 'timeout'=> 9999999 ]); ?> \r\n    <?= GridView::widget([\r\n        'dataProvider' => new ArrayDataProvider(['allModels' => [['name'=> 'bob','age'=> rand(10,80)]]]),\r\n        'columns' => ['name','age'],\r\n    ]); ?>\r\n<?php Pjax::end(); ?>\r\n\r\n<?php\r\n$this->registerJs(<<<JS\r\n$('#pjax').on('pjax:error', function (event, error) {\r\n     $('#output').append('pjax:error.statusText: ' + error.statusText + '<br>')\r\n     event.preventDefault();\r\n });\r\nJS\r\n);\r\n?>\r\n```"}}
{"actor":{"display_login":"tunecino"}}