Yii2: pjax scroll

Created on 14 Mar 2017  路  2Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

When add to link options data-method and data-pjax

Html::a(
     '<i class="fa fa-minus"></i>',
      Url::to(['/admin/roles/revoke', 'roleName' => $roleName, 'permissionName' => $model['name']]),
     [
          'data-method' => 'post',
          'data-pjax' => 1,
      ]
);

inside pjax container, after request to server, pjax scroll page to top.
If add ['data-pjax-scrollto' => true] page does not scroll. :)

What is the expected result?

No scroll page after request.

What do you get instead?

pjax scroll page to top.

Decission

In yii.js row 170-180 need replace

pjaxOptions = {
                    container: pjaxContainer,
                    push: !!$e.data('pjax-push-state'),
                    replace: !!$e.data('pjax-replace-state'),
                    scrollTo: $e.data('pjax-scrollto'),
                    pushRedirect: $e.data('pjax-push-redirect'),
                    replaceRedirect: $e.data('pjax-replace-redirect'),
                    skipOuterContainers: $e.data('pjax-skip-outer-containers'),
                    timeout: $e.data('pjax-timeout'),
                    originalEvent: event,
                    originalTarget: $e
                };

with

pjaxOptions = {
                    container: pjaxContainer,
                    push: !!$e.data('pjax-push-state'),
                    replace: !!$e.data('pjax-replace-state'),
                    scrollTo: $e.data('pjax-scrollto') !== undefined ? $e.data('pjax-scrollto') : false,
                    pushRedirect: $e.data('pjax-push-redirect'),
                    replaceRedirect: $e.data('pjax-replace-redirect'),
                    skipOuterContainers: $e.data('pjax-skip-outer-containers'),
                    timeout: $e.data('pjax-timeout'),
                    originalEvent: event,
                    originalTarget: $e
                };

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.11.2
| PHP version | 7.0.13|
| Operating system | windows/linux

JS pjax bug

All 2 comments

Got same problem on Max OS X (not surprising).

Work around for me: set global Pjax default scrollTo option to false in view file, like this:

$this->registerJs('$.pjax.defaults.scrollTo = false;', \yii\web\View::POS_LOAD);

I'm sorry to inform you that the core team has decided to stop with the support of PJAX. This implies that we are not accepting PR's for updating PJAX in the 2.0.x branch anymore. In the 2.1 branch it will be removed from the framework.

A lot has been said on this subject. Our conclusion is that the current state of PJAX does not meet our standards to properly support in the Yii framework. For this reason, we are also not moving it into a Yii2 extension. Of course the Community is free to fill this gap, but with a warning. It is very time consuming to support and in our humble opinion, it should be completely rewritten to properly meet the many usecases developers have with it.

Was this page helpful?
0 / 5 - 0 ratings