php - CArrayDataProvider with CGridView pagination Yii -


i'm trying pagination on cgridview using carraydataprovider (my $rawdata custom array - not db/model). so, in controller`s action have following:

$form = new searchuser;//here have searchuser form extends cformmodel following attributes: 'id', 'name', 'surname', 'phone', 'address' $users = array(); if (isset($_post['searchuser'])) { ....//prepare users array custom source-> not db/models etc }  $dataprovider=new carraydataprovider($users, array(             'id'=>'id',             'keys'=>array('name', 'surname', 'phone', 'address'),             'sort'=>array(                 'attributes'=>array(                     'name', 'surname', 'phone', 'address'                 ),             ),             'pagination'=>array(                 'pagesize'=>15,             ),         )); 

and:

$this->render('index', array('dataprovider'=>$dataprovider, 'form'=>$form)); 

on index.php have:

... <?php echo chtml::link('search','#',array('class'=>'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderpartial('_search',array( 'model'=>$form, )); ?> </div><!-- search-form --> <?php  $this->widget('zii.widgets.grid.cgridview', array( 'dataprovider'=>$dataprovider, 'columns'=>array(      array(         'name' => 'name',                   'type' => 'raw',         'value' => 'chtml::encode(@$data["name"])'     ),     array(         'name' => 'surname',                   'type' => 'raw',         'value' => 'chtml::encode(@$data["surname"])'     ),/*     array(         'name' => 'phone',                   'type' => 'raw',         'value' => 'chtml::encode(@$data["phone"])'     ),*/     array(         'name' => 'address',                   'type' => 'raw',         'value' => 'chtml::encode(@$data["address"])'     ), ), 'enablepagination'=> true, )); 

the first page displayed correctly when select page, filter lost , data displayed in grid instead of "filtered" ones.

not sure solve problem, in carraydataprovider use id define name of key field instead of keyfield. try following:

$dataprovider=new carraydataprovider($users, array(     'id'=>'users',     'keyfield' => 'id',      'keys'=>array('id','name', 'surname', 'phone', 'address'),     'sort'=>array(         'attributes'=>array(             'name', 'surname', 'phone', 'address'         ),     ),     'pagination'=>array(         'pagesize'=>15,     ), )); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -