Answer the question
In order to leave comments, you need to log in
How to change data using pjax?
I need to somehow update the data in the database, probably using PJAX.
I have a dropDownList in it with a list of categories. As well as GridView and checkboxes (CheckboxColumn) are displayed in it.
Here is the list of categories:
Html::dropDownList('records','null', ArrayHelper::map($listData,'id','name'),
[
'prompt' => '-- Выбрать категорию --',
'class' => 'form-control'
]);
$(document).on("click", "#bulk", function(event) {
event.preventDefault();
$.post("<?= Url::current()?>", {records: $('#grid').yiiGridView('getSelectedRows')}).done(function() {
// обновить pjax или страницу
});
});
public function actionBulk(){
if($records = Yii::$app->getRequest()->post('action')) {
Book::save(['id' => $records]);
Yii::$app->session->setFlash('success', "Категория у книги {$model->name} обновлена");
}
}
Answer the question
In order to leave comments, you need to log in
1. Where should I insert this code?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question