Closed Razip closed 5 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.
Won't be implemented in 2.0.
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!