2
我想在yii2的GridView其工作使用編輯欄,並模擬保存,但AJAX不是在編輯欄中工作和AJAX無法完成當我點擊申請按鈕阿賈克斯在編輯欄不工作在GridView的
[ 'class'=>'kartik\grid\EditableColumn',
'headerOptions' => ['style' => 'width:15%;text-align:center','class' => 'kv-sticky-column'],
'attribute'=>'name',
'pageSummary'=>true,
'vAlign'=>'middle',
'contentOptions' => ['class' => 'kv-sticky-column'],
'editableOptions'=> function ($model, $key, $index){
return [
'header'=>'Name',
'size'=>'md',
//'value'=>$model->name,
//'class'=>'has-success',
];
}
],
以上,這是我的GridView接觸和控制下面
公共功能的actionIndex() {
$searchModel = new UsersSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if(Yii::$app->request->post('hasEditable'))
{
$model =new Users();
$bookId = Yii::$app->request->post('editableKey');
$model = Users::findOne($bookId);
$post = [];
$posted = current($_POST['Users']);
$post['Users'] = $posted;
// Load model like any single model validation
if ($model->load($post))
{
// When doing $result = $model->save(); I get a return value of false
if($model->save())
{
if (isset($posted['name']))
{
$output = $model->name;
}
$out = Json::encode(['output'=>$output, 'message'=>'']);
}
}
// Return AJAX JSON encoded response and exit
echo $out;
return;
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}