手册网_shouce点ren 2015-11-16 16:50:12 4116次浏览 0条回复 0 0 0

yii CListView 是没有table表头的,如图 输入图片说明 现在需要重写CListView 在/protected/components/下添加MyCListView.php

<?php
Yii::import ( 'zii.widgets.CListView' );
class MyCListView extends CListView {
	public $preItemsTag = '';
	public $postItemsTag = '';
	public $itemsThead=array();
	public function renderItems() {
		$starHtml=CHtml::openTag ( $this->itemsTagName, array (
				'class' => $this->itemsCssClass 
		) ) . "\n";
		
		$data = $this->dataProvider->getData ();
		$data_count=($n = count ( $data ));
		if ($data_count > 0) {
			$itemsThead=$this->itemsThead;
			$theadHtml='<thead><tr>';
			foreach ($itemsThead as $i_key=>$i_value){
				$theadHtml.='<th width='.$i_value.'>'.$i_key.'</th>';
			}
			$theadHtml.='</tr></thead>';
			$starHtml.=$theadHtml;
		}
		echo $starHtml;
		
		if ($data_count > 0) {
			$owner = $this->getOwner ();
			$viewFile = $owner->getViewFile ( $this->itemView );
			$j = 0;
			foreach ( $data as $i => $item ) {
				$data = $this->viewData;
				$data ['index'] = $i;
				$data ['data'] = $item;
				$data ['widget'] = $this;
				$owner->renderFile ( $viewFile, $data );
				if ($j ++ < $n - 1)
					echo $this->separator;
			}
		} else
			$this->renderEmptyText ();
		echo CHtml::closeTag ( $this->itemsTagName );
	}
}

视图界面修改

<?php
	$this->widget ( 'application.components.MyCListView', array (
			'dataProvider' => $dataProvider,
			'itemView' => '_index/_index',
			'template' => "{items}\n{pager}",
			'itemsThead'=>array('ID'=>'5%','商品名称'=>'15%','价格'=>'6%','返利价格'=>'6%','状态'=>'6%','创建时间'=>'15%','步骤'=>'6%','操作'=>'10%'),
			'itemsTagName' => 'table',
			'itemsCssClass' => 'table table-striped table-bordered table-hover text-center td_center th_center ',
			'pagerCssClass' => 'widget-foot',
			'pager' => array (
					'class' => 'CLinkPager',
					'nextPageLabel' => '&raquo;',
					'prevPageLabel' => '&laquo;',
					'firstPageLabel' => '首页',
					'lastPageLabel' => '末页',
					'htmlOptions' => array (
							'class' => 'pagination'
					),
					'header' => '',
					'hiddenPageCssClass' => 'disabled',
					'selectedPageCssClass' => 'active'
			)
	) );
	?>

主要是新建了属性

'itemsThead'=>array('ID'=>'5%','商品名称'=>'15%','价格'=>'6%','返利价格'=>'6%','状态'=>'6%','创建间'=>'15%','步骤'=>'6%','操作'=>'10%'),

效果图 输入图片说明

原文的地址:http://www.shouce.ren/api/view/a/7938

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册