[英]Yii CArrayDataProvider does not update active page on GridView
I'm using yii bootstrap widgets TbGridView to view data from my database table. 我正在使用yii bootstrap小部件TbGridView来查看数据库表中的数据。
evry page request I get the data from my API using offset , and I update the grid view databrovider
from the result of API . evry页面请求我使用offset从我的API获取数据,然后从API的结果更新grid view
databrovider
。
I used CArrayDataProvider for that. 我为此使用了CArrayDataProvider 。
my problem is at the first request it return the records and it display all pages on pagination on grid view, and when I click on any page on pagination it return the data by offset but the grid view does not add active class on the clicked page. 我的问题是在第一次请求时它返回记录,并在网格视图上显示分页中的所有页面,当我在页面上单击任何页面时,它按偏移量返回数据,但网格视图未在单击的页面上添加活动类 。
and I was set currentPage = 0 in pagination option and if I remove this option and click on any page on pagination it return no result found Although there is a result on my Data Provider 并且我在分页选项中设置了currentPage = 0 ,并且如果我删除了该选项并在分页上单击任何页面,则不会返回任何结果,尽管我的数据提供程序上有结果
my code is : 我的代码是:
this is my data provider 这是我的数据提供者
$offset = $limit * ($page_no-1) ;
$arr_transaction = $obj_transaction->getTransactionByOffset($offset);
$total_record = $total_record = $obj_transaction->getTotalRecord();
$dp_transactions = new CArrayDataProvider($arr_transaction,
array('id'=>'transactions',
'keyField' => false,
'pagination'=>array(
'pageSize'=>10,
'params' => array('date_from' => $transaction_form->date_from,'date_to'=>$transaction_form->date_to),
'currentPage'=>0,
),
'totalItemCount'=>$total_record,
));
and this is my Grid view 这是我的网格视图
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped bordered condensed',
'dataProvider'=>$dp_transactions,
'template' => "{summary}{items}{pager}",
'enablePagination'=>true,
'columns'=>array(
array('name'=>'ust_order_Id', 'header'=>'Oreder Id'),
array('name'=>'ust_create_time', 'header'=>'Transaction Time'),
array('name'=>'ust_email', 'header'=>'Email'),
array('name'=>'ust_mobile_number', 'header'=>'Mobile Number'),
array('name'=>'ust_amount', 'header'=>'Amount'),
),
));
?>
and I don't need to supply ALL THE DATA to the CArrayDataProvide
. 而且我不需要将所有数据提供给
CArrayDataProvide
。
Any one can help me 任何人都可以帮助我
Thanks 谢谢
It is "defect" of CArrayDataProvider
: Length of your array must be bigger than (CURRENT_PAGE-1) * PAGE_SIZE
. 这是
CArrayDataProvider
“缺陷”:数组的长度必须大于(CURRENT_PAGE-1) * PAGE_SIZE
。 So you can pad empty values to your array: 因此,您可以将空值填充到数组中:
$offset = $limit * ($page_no-1) ; // it means $page_no is current page number
$arr_transaction = $obj_transaction->getTransactionByOffset($offset);
$total_record = $total_record = $obj_transaction->getTotalRecord();
$arr_transaction = array_pad($arr_transaction, -1*(count($arr_transaction) + $offset), null);
$dp_transactions = new CArrayDataProvider($arr_transaction,
array('id'=>'transactions',
'keyField' => false,
'pagination'=>array(
'pageSize'=>$limit, // $limit = 10 ?
'params' => array('date_from' => $transaction_form->date_from,'date_to'=>$transaction_form->date_to),
// 'currentPage'=>0, this not needed
),
'totalItemCount'=>$total_record,
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.