Yii Framework Forum: Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cgridview displaying a gridview in multiple gridviews yii based on some ids Rate Topic: -----

#1 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 10 October 2012 - 05:14 AM

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.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,077
  • Joined: 16-February 11
  • Location:Japan

Posted 10 October 2012 - 05:36 AM

/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */
0

#3 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 10 October 2012 - 05:53 AM

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

#4 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 340
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 10 October 2012 - 05:54 AM

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
0

#5 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 10 October 2012 - 07:21 AM

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:


View Postwaterloomatt, on 10 October 2012 - 05:53 AM, said:

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

0

#6 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 10 October 2012 - 07:26 AM

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...








View PostGerhard Liebenberg, on 10 October 2012 - 05:54 AM, said:

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

0

#7 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 340
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 10 October 2012 - 08:36 AM

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. :)
0

#8 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 10 October 2012 - 11:08 PM

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.....




View PostGerhard Liebenberg, on 10 October 2012 - 08:36 AM, said:

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. :)

0

#9 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 340
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 11 October 2012 - 03:09 AM

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?
0

#10 User is offline   Gerhard Liebenberg 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 340
  • Joined: 07-January 12
  • Location:Stillbay - Western Cape - South Africa

Posted 11 October 2012 - 04:40 AM

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.
0

#11 User is offline   waterloomatt 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 545
  • Joined: 09-April 10

Posted 11 October 2012 - 07:15 AM

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?

Attached File  many_grid.jpg (166.96K)
Number of downloads: 20


Matt
0

#12 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 12 October 2012 - 01:31 AM

Yes,Exacltly.



View Postwaterloomatt, on 11 October 2012 - 07:15 AM, said:

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?

Attachment many_grid.jpg


Matt

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users