[英]CGridView Pagination not working. Yii
I have a form in my view which selects columns from a dropdown list. 我的视图中有一个表单,该表单从下拉列表中选择列。 The SqlDataProvider is used to get the data from the generated Query
SqlDataProvider用于从生成的查询中获取数据
I have been trying to use CGridView with SQLDataProvider, its working a bit fine, but still having some issues with pagination. 我一直在尝试使用带有SQLDataProvider的CGridView,它的工作效果还不错,但是在分页方面仍然存在一些问题。 I don't have any keyField so I give it my first column, and without keyField it doesn't work.
我没有任何keyField,所以我在第一栏中给出它,没有keyField则不起作用。
Here is my action: 这是我的动作:
public function actionIndex()
{
$tables = Yii::app()->db->schema->getTables();
if(isset($_POST['yt0'])){ //if from submitted
$query = $this->generateQuery();
$count=Yii::app()->db->createCommand('SELECT COUNT(*) FROM ( ' . $query . ' ) as count')->queryScalar();
$dataProvider = new CSqlDataProvider($query, array(
'keyField' => $firstColumn,
'totalItemCount'=> $count,
'pagination'=> array(
'pageSize'=>20,
),
));
$columns = $this->getColumnNamesWithoutTable();
$this->render('index',
array( 'tables' => $tables,
'query' => $query,
'dataProvider' => $dataProvider,
'columns' => $columns
)
);
}else{
$this->render('index', array('tables' => $tables));
}
}
Here is widget code in the view, according to what I have read, pagination should work automatically, is it because I am using a custom query rather than Yii Models ? 这是视图中的窗口小部件代码,根据我所读的内容,分页应该自动运行,是因为我使用的是自定义查询而不是Yii模型?
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'enablePagination'=> true,
));
It shows the data first time, but next button doesn't work. 它第一次显示数据,但下一个按钮不起作用。
I just added totalitemcount in the sqldataprovider and it worked for me, if anyone is still wondering, 我只是在sqldataprovider中添加了totalitemcount,它对我有用,如果有人仍然想知道,
$dataProvider=new CSqlDataProvider($sql, array(
'pagination'=>array(
'pageSize'=>10,
),
'totalItemCount'=>'100000'
));
'keyField' => $firstColumn 'keyField'=> $ firstColumn
What is the $firstColumn value. 什么是$ firstColumn值。
Keyfield must be index of array retiring by the CSqlDataProvider 关键字段必须是CSqlDataProvider退出的数组的索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.