yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.92k forks source link

Adding/deleting/editing rows in GridView on the client side #15723

Closed Razip closed 5 years ago

Razip commented 6 years ago

Let's say I have a table of messages on my page. I can add messages via Ajax dynamically, and I want all of my new messages to appear in the table without loading the page, but how can one do that?

You could render the whole GridView table and send it back to the client through Ajax, but it is a bad idea because:

1) you send HTML code, not pure data. 2) you request a certain number of rows from the DB, even though your message may be the only difference, thus you request and send unnecessary data.

You could use some other approach to fetch only those messages or rows that haven't been yet shown, but in that case you face following the issues:

1) When inserting a row on the client side, it needs to look exactly the same and it needs to be as workable as other ones. 2) You need to update the paginator because new pages might've been added. 3) Even if you write such code, it may be incompatible with newer versions of Yii2, while if it were in its code base, it would be rewritten to work well with the new changes.

So, I really think there should be a native way of doing this kind of thing. Thanks for reading!

fcaldarelli commented 6 years ago

The first approach that I'd use is Pjax, but it will send html code and will make a new complete request to db (not only differences).

But I'd evaluate simplicity of pjax implementation and cons with html and bigger db load.

samdark commented 5 years ago

Won't be implemented in 2.0.