我创建了一个带复选框的表,但是它没有正常工作,增量编号不正确,电子邮件和允许连接没有正确对齐请参阅我的代码和图像
'columns'=>array(
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => 2,
'checkBoxHtmlOptions' => array(
'name' => 'ids[]',),
'value' => '$data->id',
'cssClassExpression'=>'$data->status == 0 ? "" : "hidden"',
),
array(
'header'=>'No.',
'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1', // row is zero based
),
array('header' => 'Name', 'value' => '$data->Users->name'),
array('header' => 'Email', 'value' => '$data->Users->email'),
array('header' => 'Date Requested', 'value' => 'date("M j, Y", strtotime($data->date_requested))'),
array('header' => 'Requested Connections','value' => '$data->connections_requested'),
array('header' => 'Allowed Connections','type' => 'raw','value' => '($data->status == 0) ? "<input class=\"copr-connections\" type=\"text\" name=\"connections_".$data->id."\" value=\"".$data->connections_requested ."\">" : $data->connections_accepted'),
array('header' => 'Request Status','value' => '($data->status == 0) ? "Pending" : (($data->status == 1) ? "Accepted" : "Rejected")'),
),
));
答案 0 :(得分:0)
隐藏'cssClassExpression'=>'$data->status == 0 ? "" : "hidden"',
整个表格单元格。
生成表时,每行<tr>
必须考虑相同数量的<td>
标记,或者必须使用rowspan
或colspan
属性。您的表结构类似于
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
<tr>
<!-- first td skiped, as it was hidden and table looks broken --><td>2</td><td>3</td>
</tr>
最好只是禁用复选框,否则您将无法选中。以下是执行此操作的可能解决方案:http://www.yiiframework.com/forum/index.php/topic/20495-disable-checkbox-in-ccheckboxcolumn-based-on-attribute-value/
// Extended CCheckBoxColumn class
class myCheckBoxColumn extends CCheckBoxColumn
{
public $disabled;
protected function renderDataCellContent($row,$data)
{
if($this->disabled!==null)
$this->checkBoxHtmlOptions['disabled']=$this->evaluateExpression($this->disabled,array('data'=>$data,'row'=>$row));
parent::renderDataCellContent($row,$data);
}
}
// View example
'columns'=>array(
'id',
'name',
array(
'class'=>'myCheckBoxColumn',
'name'=>'checkfield',
'disabled'=>'$data->checkfield',
),
)