PHP code example of kotchuprik / yii2-x-editable
1. Go to this page and download the library: Download kotchuprik/yii2-x-editable library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kotchuprik / yii2-x-editable example snippets
public function actions()
{
return [
'editable' => [
'class' => XEditableAction::className(),
//'scenario' => 'editable', //optional
'modelClass' => Model::className(),
],
];
}
echo \kotchuprik\xeditable\widgets\TextField::widget([
'value' => 'With XEditableText',
]);
echo \kotchuprik\xeditable\widgets\TextField::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'name' => 'title',
],
'callbacks' => [
'validate' => new \yii\web\JsExpression('
function(value) {
if($.trim(value) == "") {
return "This field is
echo \kotchuprik\xeditable\widgets\TextField::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'toggle' => 'manual',
'name' => 'title',
],
'callbacks' => [
'validate' => new \yii\web\JsExpression('
function(value) {
if($.trim(value) == "") {
return "This field is
echo \kotchuprik\xeditable\widgets\TextArea::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'name' => 'content',
],
]);
echo \kotchuprik\xeditable\widgets\Select::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'name' => 'status',
'source'=>[
[
'value' => 1,
'text' => Yii::t('app', 'On'),
],
[
'value' => 0,
'text' => Yii::t('app', 'Off'),
],
],
],
]);
echo \kotchuprik\xeditable\widgets\Date::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'name' => 'created_at',
'value' => date('Y-m-d', $model->created_at),
'format' => 'yyyy-mm-dd',
'viewformat' => 'dd/mm/yyyy',
'datepicker' => [
[
'weekStart' => 1,
],
],
],
]);
echo \kotchuprik\xeditable\widgets\DateTime::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'name' => 'created_at',
'value' => date('Y-m-d h:i', $model->created_at),
'format' => 'yyyy-mm-dd hh:ii',
'viewformat' => 'dd/mm/yyyy hh:ii',
'datepicker' => [
[
'weekStart' => 1,
],
],
],
]);
echo \kotchuprik\xeditable\widgets\ComboDate::widget([
'model' => $model,
'placement' => 'right',
'type' => 'combodate',
'pluginOptions' => [
'name' => 'created_at',
'value' => date('Y-m-d h:i', $model->created_at),
'format' => 'YYYY-MM-DD HH:mm',
'viewformat' => 'MMM DD, YYYY HH:mm',
'template' => 'DD / MMM / YYYY HH:mm',
'combodate' => [
[
'minYear' => 2000,
'maxYear' => 2015,
'minuteStep' => 1,
],
],
]
]);
echo \kotchuprik\xeditable\widgets\CheckList::widget([
'model' => $model,
'placement' => 'right',
'pluginOptions' => [
'name' => 'image',
'source' => [
[
'value' => 'option1',
'text' => Yii::t('app', 'option1'),
],
[
'value' => 'option2',
'text' => Yii::t('app', 'option2'),
],
[
'value' => 'option3',
'text' => Yii::t('app', 'option3'),
],
],
],
]);
echo \kotchuprik\xeditable\widgets\WysiHtml5::widget([
'model' => $model,
'pluginOptions' => [
'toggle' => 'manual',
'name' => 'content',
'title' => 'Enter comments',
],
]);
$items = [
[
'value' => 'gb',
'text' => Yii::t('app', 'Great Britain'),
],
[
'value' => 'us',
'text' => Yii::t('app', 'United States')],
[
'value' => 'ru',
'text' => Yii::t('app', 'Russia'),
]
];
echo XEditable::widget([
'placement' => 'right',
'type' => 'select2',
'pluginOptions' => [
'value' => 'ru',
'source'=> $items,
'select2' => [
'multiple' => true
],
]
]);
$items = [
[
'value' => 'gb',
'text' => Yii::t('app', 'Great Britain'),
],
[
'value' => 'us',
'text' => Yii::t('app', 'United States'),
],
[
'value' => 'ru',
'text' => Yii::t('app', 'Russia'),
],
];
echo XEditable::widget([
'placement' => 'right',
'type' => 'typeaheadjs',
'pluginOptions' => [
'value' => 'ru',
'typeahead' => [
'name' => 'country',
'local' => $items,
],
]
]);
$provider = new \yii\data\ActiveDataProvider([
'query' => Categories::find(),
'pagination' => [
'pageSize' => 4,
],
]);
echo GridView::widget([
'id' => Yii::$app->controller->id,
'dataProvider' => $provider,
'columns' => [
[
'value' => function($model) {
return $model->active;
},
'class' => XEditableColumn::className(),
'url' => 'editable',
'dataType' => 'select',
'editable'=>[
'source'=>[
[
'value' => 1,
'text' => Yii::t('app', 'On'),
],
[
'value' => 0,
'text' => Yii::t('app', 'Off'),
],
],
'placement' => 'right',
],
'attribute' => 'status',
'format' => 'raw',
],
'title',
],
]);