0

我的项目中有一个自定义下拉分页并使用 CListView 显示项目,但它无法正常工作。无论我在下拉列表中选择什么数字或页码,列表的内容都是空的。我可以看到摘要编号已更改并正确显示,但未显示列表。我错过了什么?

下面是模型 - CandidateSearch() 代码:

public function candidateSearch()
{
    $criteria = new CDbCriteria;

    $criteria->compare('can_id',$this->can_id);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
        'sort'=>array(
            'defaultOrder'=>'name ASC',
        ),
        'pagination'=>array(
                'pageSize'=> Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']),
        ),
    ));
}

下面是控制器代码:

public function actionIndex()
{
    if (isset($_GET['pageSize'])) 
    {
        Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
        unset($_GET['pageSize']);
    }

    $model = new JbMeetGreet('candidateSearch');
    $model->unsetAttributes();  // clear any default values
    $model->can_id = Yii::app()->user->id;
    $model->created_by = Yii::app()->user->id;
    $model->created_by_lvl = Yii::app()->user->user_level;

    //search function
    if(isset($_POST['JbMeetGreet']))
    {
        $model->attributes = $_POST['JbMeetGreet'];
    }

    $this->render('index', array('model'=>$model));
}

以下是索引页面代码:

$pageSize = Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']); 
    echo CHtml::dropDownList('pageSize',$pageSize,array(5=>5,10=>10,15=>15,20=>20,25=>25,30=>30),
    array('onchange'=>"$.fn.yiiListView.update('meet-greet-grid',{ data:{pageSize: $(this).val() }})",
    'empty'=>'-- Select Page Range --','style'=>'width:100%;'));

$this->widget('zii.widgets.CListView',array(
    'id'=>'meet-greet-grid',
    'dataProvider'=>$model->candidateSearch(),
    'itemView'=>'_profile_list',
    'template'=>'{summary}{pager}{items}',
    'summaryText'=>'Result {start} - {end} of {count} results',
});
4

2 回答 2

0

您必须将您的 dropDownList 添加到您的网格中(以使 ajax 调用工作):

// into your view

$pageSize = Yii::app()->user->getState('pageSize', Yii::app()->params['defaultPageSize']);
$perPagina = CHtml::dropDownList('pageSize', $pageSize, array(5=>5,10=>10,15=>15,20=>20,25=>25,30=>30),
        array('onchange' => "$.fn.yiiGridView.update('meet-greet-grid',{ data:{pageSize: $(this).val() }})")
    );

$this->widget('zii.widgets.CListView',array(
    'id'=>'meet-greet-grid',

    // add this
    'header' => $perPagina,

    'dataProvider'=>$model->candidateSearch(),
    'itemView'=>'_profile_list',
    'template'=>'{summary}{pager}{items}',
    'summaryText'=>'Result {start} - {end} of {count} results',
});

于 2019-12-09T09:26:20.643 回答
0

我设法解决了它。我的项目视图页面中有动画。删除了动画代码,显示后续页面中的数据。谢谢你。

于 2019-12-12T05:54:35.140 回答