pagination is not working with arraydataprovider

pagination is not working if i m using arraydataprovider and in this i m passing query that is custom array

$provider = new ArrayDataProvider([

          'key' => 'id',  


         'allModels' => $retVal,


         'pagination' => [





     'pageSize' => 50,


],

]);

here $retVal array is custom array not coming from database directly

and in this i have following

yii\data\ArrayDataProvider Object

(

[key] => id


[allModels] => Array


    (


        [1] => Array


            (


                [id] => 1


                [time] => 03-05-2015 14:43:15


                [speed] => 31 Km/hr


                [address] =>''


            )

in grid on first page it is showing fine but when i click on 2nd page data lost,nothing is coming.

i dont know where is my mistake or i m missing some setting.

plz i need help on this

Well, here is a working example. You can copy and paste it in a view to see it work. Compare yours to this…it could be that you have more than one grid view on the page and you are not setting your ‘id’ value… maybe?




	<?php

	$retVal = [

    	[ 'id' => '1', 'speed' => '100', 'time' => '03-05-2015 05:15:17', 'address' => '123 Main St.'],

    	[ 'id' => '2', 'speed' => '110', 'time' => '03-06-2015 17:43:23', 'address' => '456 Park St.'],

    	[ 'id' => '3', 'speed' => '120', 'time' => '03-07-2015 11:33:35', 'address' => '789  Oak St.'],

    	[ 'id' => '4', 'speed' => '130', 'time' => '03-08-2015 14:10:55', 'address' => '987 1st St.'],

    	[ 'id' => '5', 'speed' => '140', 'time' => '03-08-2015 16:23:15', 'address' => '654 Broad St.'],

	];


	$provider = new yii\data\ArrayDataProvider([

    	'allModels' => $retVal,

    	'key' => 'id',

    	'sort' => [

        	'attributes' => ['id', 'speed', 'time', 'address'],

    	],

    	'pagination' => [

        	'pageSize' => 3,

    	],

	]);


	echo yii\grid\GridView::widget([

    	'id'=>'my-grid',

    	'dataProvider' => $provider,

    	'columns' => [

        	'id',

        	'speed',

        	[

            	'attribute' => 'time',

            	'label' => 'Time',

            	//'format'=>'datetime',

            	'format' => ['date', 'php:M d, Y \a\t H:i:s A'

            	],

        	],

        	'address'

    	]

	]);

	?>



You can

i m getting my retVal array from user search criteria ,it is coming from get method not post ,will this effect pagination

i m sry but your given example is not working ,below is my code ,i m using get method then it is working if i use post by default it is,not working with pagination,




 <?php $form = ActiveForm::begin([

            'method' => 'get',

            'action' => ['report/speed-report-view'],

            'options' => ['class' => 'form-horizontal'],

            'fieldConfig' => [

            'template' => "{label}\n<div class=\"col-xs-8\">{input}{error}</div>",

            'labelOptions' => ['class' => 'col-xs-3 control-label'],

            ],

            ]); ?>

              <div class="row">

                <h4 class="col-md-8" >


                 <i class="lg fa fa-area-chart"></i>

                 <strong> 1. Device Info</strong>

               </h4>

               <div class="col-md-12 " style="height: 10px;"></div>

               <div class="col-lg-12">

                <div class="form-column col-md-6">


                <?php  echo $form->field($model, 'vehicle_id')->widget(Select2::classname(), [

                    'data' => vehicle::getData(),


                    'language' => 'en',

                    'options' => ['placeholder' => Yii::t('app','Select Device')],

                    'pluginOptions' => [

                    'allowClear' => false

                    ],

                    ]);?>


                <?php  echo $form->field($model, 'speed')->widget(Select2::classname(), [

                    'data' => $model->getspeed(),

                    'language' => 'en',

                    'options' => ['placeholder' => Yii::t('app','Select min speed')],

                    'pluginOptions' => [

                    'allowClear' => false

                    ],

                    ]);?>           

                </div>

                <div class="form-column col-md-6"> 

                    <?php

                    echo $form->field($model, 'start_date')->widget(DatePicker::classname(), [

                        'pluginOptions' => [

                        'endDate'=>'0d',

                        'autoclose' => true,

                        'format' => 'dd-mm-yyyy'

                        ]

                        ]);?>

                    <?php

                    echo $form->field($model, 'end_date')->widget(DatePicker::classname(), [

                        'pluginOptions' => [

                        'endDate'=>'0d',

                        'autoclose' => true,

                        'format' => 'dd-mm-yyyy '

                        ]

                        ]);?>

                 </div>

                 </div>  

                 </div>      

                <div class="clearfix">

                    <div class="col-md-12 form-actions">

                        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Generate') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

                        &nbsp; &nbsp; &nbsp;

                        <button type="reset" class="btn">

                            <i class="ace-icon fa fa-undo bigger-110"></i>

                            Reset

                        </button>

                    </div>

                </div>

                <?php ActiveForm::end(); ?>



and this form is custom form

The snippet I posted works by itself.

Post the controller action and search model / function because I’m not understanding what you’re asking

this is problem

When a form is submitted (with method=post) to the server, that’s one POST request. If you want to make another POST request, you need to make another POST request. If you click a link, that’s not a POST request.

because yii pagination also works on get method,see when we click on pagination what url shows at top

backend/web/index.php?r=account%2Faccount%2Findex&page=3

from here it takes page and page and param

Well you should post your model, view & controller and tell us what’s working and what’s not and what you are trying to accomplish.

You are making a lot of different post for the same actions it appears. You should make one that list all of the issues. You will get a more complete answer that works with all of your issues. If you don’t do this you will get an answer that fixes one issue but breaks something else, thus, wasting time for the posters trying to help you and yourself.

However, you should be able to use pjax


$.pjax.reload({url: url, method: 'POST', container:'#my-grid-pjax'});