I have some filter per-page and gridview.
They placed in pjax.
When i change some pagination and sort and after that use my per-page filter - params from pagination and sort are lost.
I want to save it. How to do that?
My code:
<?php Pjax::begin(['id' => 'pjax']) ?>
<?= Html::dropDownList('per-page', Yii::$app->request->get('per-page') != NULL ? Yii::$app->request->get('per-page') : [10 => 10], [1 => 1, 5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100], [
'onchange' => '
$.pjax.reload({
url: "'.Url::to([Yii::$app->controller->action->id, 'id' => Yii::$app->request->get('id')]).'?StandartSearch%5Bdate%5D=" + $(\'#date\').val() + "&per-page=" + $(this).val(),
container: "#pjax",
});
',
'class' => 'form-control',
'id' => 'per-page'
]) ?>
<?= GridView::widget([
'id' => 'gridview',
'dataProvider' => $dataProvider,
'columns' => [
// columns
],
]); ?>
<?php Pjax::end() ?>
Per-page filter are placed within pjax container. So obviously they will get lost when pjax event is completed.
To make them not to lost their current selection, you can place per page filter in the form outside pjax.
and $formSelector property on pjax which points to that filter form id.
reference: http://www.yiiframework.com/doc-2.0/yii-widgets-pjax.html#$formSelector-detail
Related
i have a depdrop in my project like
<?= $form->field($model, 'neighborhood_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map($query,'id','placeWithCity'),
'options' => ['placeholder' => 'Select Your Neighborhood','id'=>'select_place'],
])->label(false); ?>
And
<?=$form->field($model, 'building_id')->widget(DepDrop::classname(), [
'data' =>ArrayHelper::map(Buildings::find()->all(),'id','buildingWithPlace'),
'options' => ['placeholder' => 'Select The Building','id'=>'select_building'],
'type' => DepDrop::TYPE_SELECT2,
'pluginOptions' => [
'depends' => ['select_place'],
'url'=>Url::to(['property-commercial-rent/buildings']),
'loadingText' => 'Loading buildings ...',
]
])->label(false);?>
The second dropdown is depend on the first one.Initially they both have full list of data without any filtering.When i select a neighborhood in the first dropdown then the second populates with the building names under that neighborhood. Then i have a reset button like and has an action like
$( "#reset-location" ).click(function() {
$(select_place).val('').trigger('change');
$(select_building).val('').trigger('change');
});
And this click resetting the both select.BUt the problem is the building has only the items under the previously select neighborhood.I want the make it all like initial stage.How can i do this
You don't need a reset button. On the neighbourhood field allow clear, so it would be like this
<?= $form->field($model, 'neighborhood_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map($query,'id','placeWithCity'),
'options' => ['placeholder' => 'Select Your Neighborhood','id'=>'select_place'],
'pluginOptions' => [
'allowClear' => true
],
])->label(false); ?>
Then there will be a x in the field to clear it.
I used to use kartik in many projects and its working fine even in popup modal , but in this way I do not know why
in controller
$model = new LogFile();
$file_position= $_GET['file_position'];
$canTransferTo = new CourtDepartment();
$canTransferTo = CourtDepartment::find()
->where(['id'=>$file_position])
->one();
$CourtDepartment = CourtDepartment::find()
->where('id in ('. $canTransferTo->canTransferTo.')')
->all();
in my _form.php
<?= $form->field($model, 'move_to')->widget(\kartik\widgets\Select2::classname(), [
'data' => \yii\helpers\ArrayHelper::map($CourtDepartment
, 'id', 'name'),
'options' => ['placeholder' => Yii::t('app', 'Choose Court department')],
'pluginOptions' => [
'allowClear' => true
],
]); ?>
when i click the button
<?= Html::button(Yii::t('app', 'Move File'), ['value' => Url::to(['log-file/create','rippId'=>$model->rippId, 'file_position'=>$model->file_position]),'class' => 'btn btn-primary addNew', 'id'=>'addNew']); ?>
i get this message in console
GET http:[My Site Name]?r=log-file%2Fcreate&rippId=1-10-151&file_position=2 500 (Internal Server Error)
but if i open the link in new tab its works fine
In my yii2 project, I'm using Pjax GridView.
My index page:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'batch',
[
'attribute' => 'file_import',
'format' => 'raw',
'value'=>function ($data) {
return Html::a($data->file_import, ['/device/index', 'DeviceSearch', 'batch' => $data->batch]);
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
The link in the file_import column goes to http://localhost/index.php/device/index?1=DeviceSearch&batch=200325806610154437. But in this url, all the data is showing instead of showing only the search result. I wanted to set the file_import column as an url which will show only the search result by the provided parameter in the url.
Thank you in advance.
Change URL route to
['/device/index', 'DeviceSearch[batch]' => $data->batch]
I use redactor for editing comment. There are multiple redactors since there are multiple comments. Most of the time, redactor is loaded, but sometimes the redactor is not loaded and only generate normal text editor.
These comments are loaded after Pjax Request
My code:
<?= \yii\redactor\widgets\Redactor::widget([
'name' => 'comment',
'value' => \yii\helpers\HtmlPurifier::process($comment),
'clientOptions' => [
'imageUpload' => \yii\helpers\Url::to(['/redactor/upload/image']),
],
]) ?>
Problem solved:
You have to put ID :)
<?= \yii\redactor\widgets\Redactor::widget([
'id' => 'edit_redactor_' . $comment_id,
'name' => 'comment',
'value' => \yii\helpers\HtmlPurifier::process($comment),
'clientOptions' => [
'imageUpload' => \yii\helpers\Url::to(['/redactor/upload/image']),
],
]) ?>
$form = ActiveForm::begin();
..
echo Editable::widget([ //this break outter form, because this generate another form
'name'=>'person_name',
'asPopover' => true,
'value' => 'Kartik Visweswaran',
'header' => 'Name',
'size'=>'md',
'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...']
]);
ActiveForm::end();
So, I tried,
echo Form::widget([
'model'=>$model,
'form'=>$form,
'columns'=>1,
'attributes'=>[
'title'=>[
'label'=>false,
'type' => Editable::INPUT_TEXT,
'widgetClass' => Editable::className(),
'options' => [
'asPopover' => true,
]
],
]
]);
but, it shows input box all the time, not editable text.
how can I use editable widget inside form? without breaking outter form?
You can try this way:
<?= $form->field($model, 'person_name')->Editable::widget([
'name'=>'person_name',
'asPopover' => true,
'value' => 'value',
'header' => 'Name',
'size'=>'md',
'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...']
]);
?>
Note : Not tested yet.