2016-01-09 57 views
0

我創建了一個表複選框,但它不工作的增量數不oming正確和電子郵件,並允許連接不正確對齊,請看看我的代碼和圖片enter image description hereYii的CCheckBoxColumn不能正常工作

'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

你隱藏與'cssClassExpression'=>'$data->status == 0 ? "" : "hidden"',整個表格單元格。

當您生成表的每一行<tr>必須考慮的<td>標籤數量相等或必須使用rowspancolspan屬性。您的表結構看起來像

<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', 
    ), 
)