Cgridview

How to display a gridview obtained from CActiveDataProvider into multiple gridviews based on any id.For e.g

We have a table as follows

1 Beckham Soccer

1 Van Persie Soccer

2 Federer Tennis.

Now I want to convert this grid into two grids on the basis of gameids(1 and 2).

The result should be two grids with the first two rows in one grid and the last one in another grid.

[color="#008000"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]

Have 2 grids and 2 data providers - each data provider will perform a query with a condition - gameType = $typeId

In your controller’s admin action, you normally create an empty model, which is used to store data that is used for filter the records of the CGridView.

This time you will simply create two empty models and then set their gameid.

$model1->gameid = 1;

$model2->gameid = 2;

Then you render your form containing two separate gridviews, and you pass both of these models to the form. Each gridview will use a different model to filter its records.

Check this wiki to see more detail about what I said above:

CGridView, CListView and CActiveDataProvider

Check this wiki to see how to have two gridviews on one form:

Dynamic GridViews

Well just for the sake of writing ,I have mentioned that number of grids must be 2.In the real situation it might be n depending upon the data.Then how many grids I will be generating :rolleyes:

Well,in the real scenario,these things are happening.

First I am doing a search operation using controller and CDbCriteria. Then I get the desired output as elicited in the post.Now My task is to display these individual grids on the same form.So,please show me an example with a generalised one,not a specific one with two grids…

I would try something like this:

In the controller, you work out how many gridviews you need and create an empty model for each gridview. Then set the filtering parameters on these empty models e.g.

$model1->gameid = 1;

$model2->gameid = 2;

$model3->gameid = 3;

Then pass all these models to a MasterView.

In the MasterView, I would have a section that tests what models were received. For each model received, I would render a subView, which contains the CGridView for that model.

The fastest way to learn Yii is to work out complex stuff like this. Then come back here and tell us how you did it. :)

As a matter of fact I don’t know how many grids I will need as all depends on the database.So,how to perform then…

Too many CgridViews on the same page could not be a good idea. So maybe you should limit the gridviews to two or three at a time. Then you could have several views with each having two or three gridviews.

But how is your DB structured? Why don’t you know beforehand how many gridviews you will need?

OK, so you have a table with many games in it. You don’t know how many. But each game in the table needs to be displayed on a separate gridview.

To me that sounds like the classic parent-child gridview scenario: You have a parent gridview - displaying all the games. If the user clicks on a game, a second gridview is displayed with more details for that specific game only.

This way you only have 2 gridviews - instead of an unknown amount.

Check the "Dynamic GridViews" wiki I mentioned above, which will show you how to do parent-child gridviews.

Can you explain in a bit more detail what you’re trying to accomplish? Would a simple drop down filter on GameType work?

I recently had to display a list of inventories and their respective sales. I rendered the list of inventories in a ListView and each inventory displayed a grid of sales data. Is this what you mean?

3319

many_grid.jpg

Matt

Yes,Exacltly.