Gii CRUD template for Single Page Ajax Administration for yii2
- Create, read, update, delete in onpage with Ajax
- Bulk delete suport
- Pjax widget suport
- Export function(pdf,html,text,csv,excel,json)
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist johnitvn/yii2-ajaxcrud "*"
or add
"johnitvn/yii2-ajaxcrud": "*"
to the require section of your composer.json
file.
For first you must enable Gii module Read more about Gii code generation tool
Because this extension used kartik-v/yii2-grid extensions so we must config gridview module before
Let 's add into modules config in your main config file
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
]
]
You can then access Gii through the following URL:
http://localhost/path/to/index.php?r=gii
and you can see Ajax CRUD Generator
Other Links Free download wordpress theme Free download html template
You can create a button to update a select2 field with a new item like below, using the attribute
tag.
Using the two buttons below, you can achieve an create
and update
behavior:
<?= Html::a('<i class="glyphicon glyphicon-plus"></i>', ['/person/create'],
['role'=>'modal-remote', 'data-modal' => '#ajaxCrudPrograma', 'title'=> 'Create new Person','class'=>'btn btn-default form-control',
'style' => ($model->person_id) ? 'display: none' : '',
'attribute' => Html::getInputId($model, 'person_id'),
'aftersave' => "$('#".Html::getInputId($model, 'some_field')."').val(response.dataId);",
]); ?>
Or refresh the modified item on select2 field:
<?= Html::a('<i class="glyphicon glyphicon-pencil"></i>', ['/person/update'],
['role'=>'modal-remote', 'data-modal' => '#ajaxCrudPrograma', 'title'=> Yii::t('app','Edit').' '.Yii::t('app','Person'),'class'=>'btn btn-default form-control','id' => 'person-update', 'tabindex' => -1,
'attribute' => Html::getInputId($model, 'person_id'),
'style' => (!$model->person_id) ? 'display: none' : '',
'type' => 'update',
'aftersave' => "$('#".Html::getInputId($model, 'some_field')."').val(response.dataId);",
]); ?>
The modal window will retrieve the create
or update
form. When you save, you can return two parameters (dataId and dataText
) to update the attribute
:
//Piece of the actionCreate of the PersonaController
if($request->isGet){
return [
'title'=> "Create new Person",
'content'=>$this->renderAjax('create', [
'model' => $model,
]),
'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left dismiss-modal']).
Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])
];
}else if($model->load($request->post()) && $model->save()){
return [
'forceClose'=> true,
'dataId' => $model->person_id, <------- HERE
'dataText' => $model->name,
];
}else{
return [
'title'=> "Create new Person",
'content'=>$this->renderAjax('create', [
'model' => $model,
]),
'footer'=> Html::button('Close',['class'=>'btn btn-default pull-left dismiss-modal']).
Html::button('Save',['class'=>'btn btn-primary','type'=>"submit"])
];
}