Master-detail table with AJAX detail load using CGridView?

Hi there,

I need to design solution that master data will be presented in CGridView (preferably), table or any other tabular solution and each table row should contain "show details" button or link, which, when clicked would slide down next rows, and insert into newly created space (new row) a result of AJAX request.

I’m asking if this can be done either directly on CGridView or in some new class extending from it or if CGridView isn’t suitable for this and the solution should be written differently from scratch.

Another option would be not to use AJAX at all, but to preload whole data into hidden rows and then only un-hide them with each click. But I have a serious doubts about performance in this case. If user will setup his view to display 100 rows on each page my code will have to preload data for both master and detail elements for all 100 rows while user will probably use one or two rows to see details. That’s why I’m sceptic to preload scenario.

I advice you to use CListView.

With a bit of work and fantasy it can be arranged to work like CGridView, with the hige advantage that you are free to write the code you want for the row.

About preload, both solution are possible. I prefer to preload if possible, you change a small request in a big request, but using ajax you will have anyway more request.

The question is: better one big request or 1 smaller and 3-4 ajax request?

Thank you for your proposition. Yes, indeed this seems to be good solution.

In relevance to CGridView, CListView also supports pagination and sorting, which is a good idea. But, if I’m not mistaken - I will have to code wonderful CGridView filtering support myself to have it in CListView, right?

Really , it’s a good idea.

We need to see more examples about Master-Detail using Yii.


Yes we need that!

Is there any idea ?

You need to be patient! :] Not every problem is related to every developer and not for every question, you’ll receive answer within a few minutes! :}

mdomba kindly gave me some ideas and examples, if I only get time (can’t promise, if this will be before Christian Christmas) to work it out I will for sure draw a short Wiki article about it or post examples of the code here. But, please be more patient! :]

OK. I will Trejder,

I am waiting the examples.



Did you got any examples? is too long wait… from last 2 weeks… i m searching for the same option… but no luck… if anyone can help… it will be big favor… this is weird that developers in this community dont like to share their knowledge…

Actually, this site is filled with developers sharing their knowledge. Trejder stated that if he had time (no promises), he would put something together. People seem to forget that this is entirely voluntary. My guess is that most people have jobs and other commitments that have to take priority.

Having said that, the best way to learn is to try and come up with a solution yourself. Start small and code examples to test what you’re doing. Then put it all together. Don’t wait for two weeks. Learn for two weeks. If you get stuck, post your code and questions and someone might (no promises) be able to help you along.