yii 重写 CListView 追加 table 表头 [ 技术分享 ]
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' => '»',
'prevPageLabel' => '«',
'firstPageLabel' => '首页',
'lastPageLabel' => '末页',
'htmlOptions' => array (
'class' => 'pagination'
),
'header' => '',
'hiddenPageCssClass' => 'disabled',
'selectedPageCssClass' => 'active'
)
) );
?>
主要是新建了属性
'itemsThead'=>array('ID'=>'5%','商品名称'=>'15%','价格'=>'6%','返利价格'=>'6%','状态'=>'6%','创建间'=>'15%','步骤'=>'6%','操作'=>'10%'),
效果图
共 0 条回复
没有找到数据。
手册网_shouce点ren
注册时间:2015-11-14
最后登录:2016-04-22
在线时长:3小时30分
最后登录:2016-04-22
在线时长:3小时30分
- 粉丝5
- 金钱85
- 威望20
- 积分315