How to organize an ajax request with this update to make using pjax, yii?

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 ?
July 9th 19 at 11:20
1 answer
July 9th 19 at 11:22
Solution
If you want to update GridView after sabmita of the form, then you can simply restart PJAX-container, for example:
$('#driverPjax').on('pjax:end', function() { 
$.pjax.reload({
 container : '#notes', timeout: '5000',
 }); 
});

If you need to update GridView directly after selecting from the drop-down list, then reboot function container need to hang on the event drop-down list, for example:
onChange = "$.pjax.reload({container : '#notes', timeout: '5000'});"
it will reload the container, and the data he'll get a new one ? if the reload accesses the controller again (from where this view is rendered) , then it is necessary to transfer data from the drop down list ... Can this moment not much more .... - watson_Torphy commented on July 9th 19 at 11:25
When you restart Pjax will return to the controller where rendered (if other is not specified in settings). To transfer the selected value, for example GET-ω putting it when you restart the container in the url parameter:
$.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
: made this a drop-down list
'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 what is a driver? JS variable? if Yes then what it is? - bryana.Renn commented on July 9th 19 at 11:34
:
'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
I mean here
'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
: AA duck here this driver which I pointed out earlier =) 'driver' - name for the drop-down list - watson_Torphy commented on July 9th 19 at 11:43
: why it does not want to send id to server
$('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
$.pjax.reload({id : id_driver, container : '#notes'});

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
something like this:
$.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
: thank you, helped, in this case id : id_driver don't need it ? And like anything else can be done ? or $.pjax.reload organizes a get request, and its parameters can be implemented only in the form of a link ? - watson_Torphy commented on July 9th 19 at 11:55
id : id_driver - not needed.
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
: okay, thank you, understood ) - watson_Torphy commented on July 9th 19 at 12:01

Find more questions by tags YiiAJAX