Hi all.
You need to make a request, as I understand ajax, and update the gridview pjax'ohms.
On the page there is a dropdown list
<div class="notes-form">
<?php Pjax::begin(['id' =--> 'driverPjax']) ?>
<?php $form = ActiveForm::begin(['options' =--> ['data-pjax' => true]]); ?>
<? $param = ['prompt' =--> 'Select driver', 'id' => 'dropDownList-driver']; ?>
<?= Html::dropDownList('driver', 0, $Fio, $param); ?>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</div>
As there is a grid view
<?php Pjax::begin(['id' =--> 'notes']) ?>
<?= GridView::widget([
'dataProvider' =--> $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'Fio',
'value' => function ($model) {
return $model->idDriver['Fio'];
}
],
'Cash',
'Date',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end() ?>
Now we need to update the gridview (re-form the dataProvider and serchModel), depending on the drop-down list. How it can be implemented ?
$.pjax.reload({container : '#notes', timeout: '5000', url: '....'});
and on the backend to handle this parameter as You need - bryana.Renn commented on July 9th 19 at 11:28
'prompt' => 'Select driver',
'id' => 'dropDownList-driver',
'onChange' => "$.pjax.reload({container : '#notes', url:driver});"
]; ?>
As I understand it $.pjax.reload will perform a get request with a url parameter = the selected id .
In controller actionIndex
if (Yii::$app->request->isGet) {
$id = $_GET['url'];
}
Why not define a url. When you first boot action what method of transmission is used ? In the course of the condition is triggered before the data in the url give. - watson_Torphy commented on July 9th 19 at 11:31
'driver' - name for the drop-down list
0 - the initial value,
$Fio - array 'id' => 'Fio', - watson_Torphy commented on July 9th 19 at 11:37
'onChange' => "$.pjax.reload({container : '#notes', url:driver});"
You have a link that should be in the url parameter - bryana.Renn commented on July 9th 19 at 11:40
$('body').on('click', '.btn-success', function (){
var id_driver = $('#dropDownList-driver').val();
alert(id_driver);
$.pjax.reload({id : id_driver, container : '#notes'});
});
Looking in firebug the get parameters of the request, and it only _pjax #notes id is not present, as it is possible to send here? - watson_Torphy commented on July 9th 19 at 11:46
where is he listed here? You need to make a link to restart your blazer ID and to restart it - bryana.Renn commented on July 9th 19 at 11:49
$.pjax.reload({id : id_driver, container : '#notes', url: 'site.com/default/index?_pjax=#notes&id_driver=' + id_driver}); - bryana.Renn commented on July 9th 19 at 11:52
pjax - can send GET requests (parameters in the link) and POST requests(without any parameters in the link). How to work with POST you can read in the dock at Pjax - bryana.Renn commented on July 9th 19 at 11:58