Yii Framework Forum: Showing Data From Table On A View - Yii Framework Forum

Jump to content

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

Showing Data From Table On A View Rate Topic: -----

#1 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 04 December 2012 - 04:51 AM

Hello everyone!

I want to show data from a table from database. Something very similar to CGridView, but I don't want some textfields of CGridView, the one that we use to filter data. I just need to show data in a table form. So CListView or CDetailView doesn't feed my need. The problem is sometimes there is empty column. In this case the column doesn't need to be showed. I'm looking for a widget or a way to create a widget with some properties like: colNum (means number of columns to be drawn), rowNum (means number of rows to be drawn). Surely we must use <tr> <td> to create table but we always create a table with a fixed number of rows and columns. I mean we know it at the time we write html code.

Hope you understand my words and give some suggestions.

Cheers!
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,562
  • Joined: 04-March 10
  • Location:UK

Posted 04 December 2012 - 05:43 AM

Can't you just use CGridView and specify the columns that you want?

If you're only looking to get rid of the filter boxes, you can remove those by not providing the 'filter' attribute when configuring the CGridView widget.
0

#3 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 04 December 2012 - 06:19 AM

View PostKeith, on 04 December 2012 - 05:43 AM, said:

Can't you just use CGridView and specify the columns that you want?

If you're only looking to get rid of the filter boxes, you can remove those by not providing the 'filter' attribute when configuring the CGridView widget.


Well the thing is for example the attribute period_1 is null (means we didn't provide a value). So we wouldn't specify it in the array for 'column'. I don't want to hardcode this. So the the specify of a column will dynamically depends on the actual value of the corresponding value of that column in database table. That is what I want. Is there a way to avoid hardcoding?
0

#4 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,562
  • Joined: 04-March 10
  • Location:UK

Posted 04 December 2012 - 06:31 AM

Each attribute is going to hold a separate value for each row, so it doesn't make sense to show or hide columns based on that.

If you're talking about iterating through all records in advance to determine which columns contain non-null values, it will be just as easy to implement this by preparing CGridView's column configuration dynamically than trying to implement your own grid from scratch.
0

#5 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 04 December 2012 - 08:00 AM

So, if I've understand it clearly:

you want two different view:
1/ one with a table containing a period_1 column if period_1 is not NULL Lets call it _view1.php
2/ and another one, in case period_1 is NULL, without period_1 column in the table. Lets call it _view2.php

And you want a switch filter "period_1 is NULL, period_1 is not NULL" ...

If that's it: you can use a dropdown for the filter wich calls an ajaxRequest for updating, saying, #myTableContainer. In the controller action called by ajaxRequest, use renderPartial (_view1 or _view2 depending on dropdown choice)...
Hey Ho !
Let's go !
0

#6 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 04 December 2012 - 09:15 AM

Dear Friend

The following is helpful in such scenario.

If dataProvider is $model->dataProvider(), we can make a column in the follwing way.

'columns'=>array(
	     array(
	     'name'=>'someAttribute',
	     'visible'=>(isset($model->someOtherAttribute) && $model->someOtherAttribute!=="")
		),
                )



Here someOtherAttribute may be the same someAttribute.

Regards.
0

#7 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 04 December 2012 - 09:46 AM

View PostKeith, on 04 December 2012 - 06:31 AM, said:

Each attribute is going to hold a separate value for each row, so it doesn't make sense to show or hide columns based on that.

If you're talking about iterating through all records in advance to determine which columns contain non-null values, it will be just as easy to implement this by preparing CGridView's column configuration dynamically than trying to implement your own grid from scratch.

What do you mean by saying configure columns dynamically?

I suppose to have these lines of code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'room-grid',
	'dataProvider'=>$dataProvider,
	'columns'=>array(
		'room_id', 
		'room_hotel_id',
		'room_type_id',
		'real_price',
		'period_1', // if $model->period_1 is not empty but what if period_1 empty
		'price_1',
		'period_2', // if $model->period_2 is not empty but what if period_2 empty
		'price_2',
		'period_3',
		'price_3',
		'period_4',
		'price_4',
	),
)); ?>

0

#8 User is offline   Trinh Duy Hung 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 26-October 12

Posted 04 December 2012 - 09:48 AM

View Postseenivasan, on 04 December 2012 - 09:15 AM, said:

Dear Friend

The following is helpful in such scenario.

If dataProvider is $model->dataProvider(), we can make a column in the follwing way.

'columns'=>array(
	     array(
	     'name'=>'someAttribute',
	     'visible'=>(isset($model->someOtherAttribute) && $model->someOtherAttribute!=="")
		),
                )





Here someOtherAttribute may be the same someAttribute.

Regards.


Well I think this is what I'm looking for. I'll give it a try and response as soon as possible.
Regards.
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