Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PJAX in GridView to replace ajax rendered container rather than submit whole page #99

Closed
lubosdz opened this issue Nov 2, 2015 · 15 comments

Comments

@lubosdz
Copy link

lubosdz commented Nov 2, 2015

Using PJAX consistently follows original implementation in Yii1 gridview is replaced via ajax callback.
In Yii2-Gii, however this performance-wise feature has been replaced with submitting whole page.
Since few months ago Yii2 uses PJAX natively, generated Gridviews may also take advantage of it.

lubosdz added a commit to lubosdz/yii2-gii that referenced this issue Nov 2, 2015
@samdark
Copy link
Member

samdark commented Nov 3, 2015

I'm not sure it's a good idea to enable it by default...

@samdark
Copy link
Member

samdark commented Nov 3, 2015

@yiisoft/core-developers need opinions.

@lichunqiang
Copy link
Contributor

I'm not sure it's a good idea to enable it by default...

@samdark agree with you.

@samdark samdark closed this as completed Dec 13, 2015
@SilverFire
Copy link
Member

Also agree with @samdark

@Faryshta
Copy link
Contributor

how about we include an option on the generator?

<?= $this->pjaxEnabled ? "<?php // Pjax::begin()  ?>\n" : '' ?>

@SilverFire
Copy link
Member

Unfortunately, PJAX does not always work as a charm. I think we should not try to force its usage, because it requires some additional experience

@lubosdz
Copy link
Author

lubosdz commented Dec 15, 2015

@SilverFire

Can you please specify in what cases PJAX does not work?
I am curious just from developers point of view, because I have never experienced any issues with it.

It's actually easy to add those two lines before & after gridview, only it's bothering to do it in all index files.

Of course if PJAX does not work reliably e.g. in some browsers, it should be documented and cannot be default setting.

@SilverFire
Copy link
Member

@lubosdz I didn't say that PJAX "does not work" in some cases. I'm talking about unobvious things, that "does not work as a charm" :)

Tricky places:

  • to make it work with forms, you have to add data-pjax="1" attribute;
  • to disable PJAX for the link, you have to add data-pjax="0" attribute;
  • when you navigate with PJAX, you must take care about the main pjax-container id (default to sequential Yii2 widget id), otherwise PJAX may break layout;
  • nesting PJAX is generally a tricky thing;
  • etc.

So enabling it by default increases entering threshold

@lichunqiang
Copy link
Contributor

You can make it yourself template

Gii is good enough to let our using custom template:

'crud' => [
    'class' => 'yii\gii\generators\crud\Generator',
   'templates' => [
       'mytemplate' => '@common/components/generators/curl/custom'
   ]
]

@Faryshta
Copy link
Contributor

But if we include it as an option for the generator and have that option disable by default then we are not forcing the usage of Pjax.

We can just encapsulate the GridView widget on the crud generator and create it with an automatically generated id.

It can be 100% backwards compatible and the use case is very well defined.

@lubosdz
Copy link
Author

lubosdz commented Dec 16, 2015

Guys, your are missing point of this thread - this was NOT enabling PJAX everywhere.
Only in Gridview, which does not do any tricky stuff like nesting, or submitting HTML forms.
This whole issue was about adding 2 lines of code into Yii code generator for "index.php file".

I know one can create custom template(s) - but when default functionality works fine - why could it not be included? The reason for this to avoid submitting whole page and make Gridview functionality consistent with Yii1 (there was also only ajax submit, not whole page like now in Yii2).

@SilverFire
Copy link
Member

Only in Gridview, which does not do any tricky stuff like nesting, or submitting HTML forms.

GridView has links (view, update, etc) and form (search).

Okay, let's make one more call for @yiisoft/core-developers opinion. Team?

@samdark
Copy link
Member

samdark commented Dec 16, 2015

It may do tricky stuff with nesting. Admin panels could get it complicated. I'm still for not enabling it by default.

@Faryshta
Copy link
Contributor

@samdark it doesn't need to be enabled by default. we can have a configuration in gii and that would be enough.

@samdark samdark reopened this Dec 16, 2015
@samdark
Copy link
Member

samdark commented Dec 16, 2015

OK. Disabled by default but configurable sounds fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants