I have a view that has two elements: one datepicker and one gridview.
I am not using any model.
When i change a date in the date picker i call an yii2 action that returns a Json encoded array. I can see this data on the success function but i don´t know how to load this data on the gridview.
My view code is:
<?= DatePicker::widget(
[
'name' => 'date',
'id' => '_date',
'type' => DatePicker::TYPE_COMPONENT_APPEND,
'value' => date('M-Y'),
'pluginOptions' => [
'autoclose'=>true,
'startView'=>'year',
'minViewMode'=>'months',
'format' => 'M-yyyy',
],
'pluginEvents' => [
"change" => "function()
{
$.ajax({
url: '".yii\helpers\Url::toRoute("planning/populate")."',
method:'GET',
dataType:'json',
data: {seldate:$('#_date').val()},
success: function (data) {
// alert(data);
}
});
}",
]
])?>
</div>
<p style="width: 100%; min-height: 45px">
</div>
<?=GridView::widget([
'dataProvider' => $dataProvider,
]);
If i use browser inspection i can see that the action that i am calling is returning the correct array in json encode format in the data variable on the success functio.
The problem is that i don’t know how to use this data in the gridview.