$("#change").on("click", function(e){
e.preventDefault()
var keys = $("#w0").yiiGridView("getSelectedRows");
$.ajax({
url: "'. \yii\helpers\Url::toRoute(['/product/exist']) .'",
type: "POST",
data: {id: keys},
success: function(){
$("input").parent().parent().removeClass("danger")
$("input:checked").prop("checked", false)
}
})
});
<span style="color:#090" title="Товар в наличии" class="glyphicon glyphicon-ok"></span>
<span style="color:#c11" title="Товар отсутсвует" class="glyphicon glyphicon-remove"></span>
// GirdView column
[
'attribute' => 'status',
'contentOptions' => function($model, $key, $index, $column){
return [
'class' => 'status-column',
'style' => 'cursor:pointer',
'id' => $key,
'onclick' => '
$.ajax({
url: "' . Url::toRoute('/ajax/update-status-mark') . '",
method: "POST",
data: {id: ' . $key . ', status: ' . $model->status . '},
success: function(data){
if(data == 0){
$("td#' . $key . ' span").removeClass("label-success").addClass("label label-danger").text("Blocked")
$("tr[data-key=' . $key . ']").removeAttr("style")
}
else{
$("td#' . $key . ' span").removeClass("label-danger").addClass("label label-success").text("Active")
$("tr[data-key=' . $key . ']").css("backgroundColor","rgb(226, 243, 227)")
}
}
})
'
];
},
]
// Controller action
public function actionUpdateStatusMark($id)
{
$model = $this->findModel($id);
$model->status = $model->status == 0 ? 1 : 0;
$model->save(false,['status']);
return $model->status;
}