[SOLVED] Customising "No results found" in CListView

Hey everyone,

I am trying to customise CListView to meet my needs.

Basically on a page of an item from the DB (let’s say a series) I have sub items (let’s say books).

I decided to use the CListView to display these sub items on their parent form.

The problem I am finding is that I have made the CListView display like a table (since the CGridView did not fit our needs) and the "no results found" shows an empty table.

Is there a way I can, in the template or something, count the amount of rows found and if no results found will be shown tell the CListView to not show certain parts of my template?

I have provided an example below:






				<table class="list_sub_objects_in_series" style='width:100%;' cellspacing="0" cellpadding="0"><thead>




						<th>sub title</th>



						<th>Shown on website</th>


				</thead><tbody>{items}</tbody><tfoot><tr><td colspan="6">{summary} {pager}</td></tr></tfoot></table>


				$list_template = ob_get_contents();


			$this->widget('zii.widgets.CListView', array(

			    'dataProvider'=>new CActiveDataProvider("Title", array(






			    'itemView'=>'_titles',   // refers to the partial view named '_post'








The main problem here is that "no results found" is shown above an empty table with this template.

Basically I am trying to hide the <table> element within the widget when no results are found.

Thanks in advance,

Sounds to me CGridView (zii.widgets.grid.CGridView) might be a better option here, instead of changing CListView until it behaves like CGridView :)

Just don’t show the widget at all if $model is empty:

<?php if (!empty($model)) : ?>

  <!-- show the list view //-->

<?php else: ?>

<p class="nodata"><?php echo 'No data to display'; ?></p>

<?php endif; ?>

Thanks for the replies,

@ScallioXTX, the problem with CGridView is that is seems to show that filtering form no matter what. This is normally ok but when I have the parent form as "Series" with sub objects of "Series" the two forms collide and ruin the page due to the way I must display the form.

@jacmoe Yea I am turning towards this path now actually, just make the CActiveDataProvider within the model and if it is empty don’t show at all. Thanks for re-enforcing my latter idea.

There is the property emptyText.

Is easy to find out such stuff, you can just type CListView in the api search and give a glance to the properties

@zaccaria, the problem with using empty text is that it just defines what is shown instead of "No results found".

Due to the way my template works it still shows the table below. That’s why I didn’t use it originally because it doesn’t mould the template around whether or not the dataprovider is empty it just dictates the text to be shown.

Sorry, I didn’t read carefully.

Therefore I guess that the only way is jacmoe’s one.

$this->widget('zii.widgets.grid.CGridView', array(


  // ...



lol I never actually saw that.

Sometimes it is quite easy to miss these little things :).

I have done a mix of these two now so as the create the best GUI effect on my site which has worked out well for me :).

Thanks for all the help people,