2014-05-20 73 views
0

我在我的代碼中有兩個問題: 1)當您點擊它時,您無法通過標題「標題」進行排序。 2)你可以點擊標題,認爲這將按字母順序排序,箭頭出現,但沒有任何反應,沒有排序。 enter image description hereCGridView列中的鏈接

網站/ index.php文件

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider, 
    'columns' => array(
     'title' => array(
      'class'=>'CLinkColumn', 
      'labelExpression' => '$data->title', 
      'urlExpression'=>'Yii::app()->request->baseUrl."/page/".$data->id', 
      'header'=>'Title', 
      'headerHtmlOptions' => array('style'=>'width:250px;'), 
     ), 
     'created' => array(
      'name' => 'created', 
      'value' => 'date("j.m.Y H:i", $data->created)', 
      'headerHtmlOptions' => array('style'=>'width:90px;'), 
     ), 
     'category_id' => array(
      'name' => 'category_id', 
      'value' => '$data->category->title', 
      'filter' => Category::allCategory(), 
      'headerHtmlOptions' => array('style'=>'width:150px; text-align:center;'), 
     ), 
     'subcategory_id' => array(
      'name' => 'subcategory_id', 
      'value' => '$data->subcategory->title', 
      'filter' => Subcategory::allCategory(), 
      'headerHtmlOptions' => array('style'=>'width:150px; text-align: center;'), 
     ), 
     'condition_id' => array(
      'name' => 'condition_id', 
      'value'=> '$data->condition->title', 
      'filter' => Condition::allAttributes(), 
      'headerHtmlOptions' => array('style'=>'width:90px;'), 
     ), 
    ), 
)); 

SiteController

public function actionIndex() 
    { 
     $dataProvider=new CActiveDataProvider('Page', array(
      'criteria'=>array(
       'order'=>'id DESC', 
      ), 
      'pagination'=>array(
       'pageSize'=>30, 
      ), 
     )); 

     // renders the view file 'protected/views/site/index.php' 
     // using the default layout 'protected/views/layouts/main.php' 
     $this->render('index', array('dataProvider'=>$dataProvider)); 
    } 

該控制器還沒有模型。

回答

0

修改您的數據提供程序像這樣的東西

$dataProvider=new CActiveDataProvider('Page', array(
      'criteria'=>array(
       'order'=>'id DESC', 
      ), 
      'sort' => array(
       'attributes' => array(
        'title', 
       ), 
      ), 
      'pagination'=>array(
       'pageSize'=>30, 
      ), 
     )); 

CLinkColumn不支持排序,只有CDataColumn確實 看到CDataColumnCLinkColumn,您可以使用原始類型進行排序鏈接,而不是下面

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider, 
    'enableSorting'=>true, 
    'columns' => array(
      'title' => array(
        'name'=>'title', 
        'headerHtmlOptions' => array('style'=>'width:250px;'), 
        'type'=>'raw', 
        'value'=>'CHtml::link($data->title,Yii::app()->request->baseUrl."/page/".$data->id)' 
      ), 
+0

Manquer,沒有任何反應! –

+0

'排序'=>數組( '屬性'=>數組( '標題', '創造', 'CATEGORY_ID', 'subcategory_id', 'condition_id', ), –

+0

標題 「標題」不會顯示爲鏈接而不是文本,並且必須是鏈接 –