Showing Data From Table On A View

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.


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?

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.

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)…

Dear Friend

The following is helpful in such scenario.

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




	     'visible'=>(isset($model->someOtherAttribute) && $model->someOtherAttribute!=="")



Here someOtherAttribute may be the same someAttribute.


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(








		'period_1', // if $model->period_1 is not empty but what if period_1 empty


		'period_2', // if $model->period_2 is not empty but what if period_2 empty







)); ?>

Well I think this is what I’m looking for. I’ll give it a try and response as soon as possible.