Filter Placeholders with Yii2 [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Does anyone know how to implement a placeholder or tooltip on the Gridview filter of the Yii2 Framework? I need something that stands out to the user to let them know that textbox is in fact a search filter.
Look forward to hearing responses.

Placeholder could be realized with this:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'name',
'filterInputOptions' => [
'class' => 'form-control',
'placeholder' => 'Type in some characters...'
]
],
['class' => 'yii\grid\ActionColumn' ],
],
]); ?>
class should be provided, though it is not a must - it is just the default styling class.
Setting this globally
The only way that I found is in config/web.php that is used for the application configuration:
$config = [
...
'on beforeRequest' => function ($event) {
Yii::$container->set('yii\grid\DataColumn', [
'filterInputOptions' => [
'class' => 'form-control',
'placeholder' => 'Type in some characters...'
]
]);
},
...
];
This is an event handler. On each request DataColumn will be configured to use the placeholder. Some detail information can be found here. Now you don't need to adjust any GridView configuration in order to have the placeholder. In the handler you can change other configurations as well, of course.

yon can also use the tooltip/title with filterOptions
[
'attribute' => 'name',
'label' => 'labelname',
...
....
'filterOptions' => [ 'title' => 'prova'],
],

Related

Calendar in Zend Framework dynamique [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
I looking to create two custom calenders with Zend Framework, i am hoping the end date (if input is not empty) is bigg than begin date.
If user set end date small than begin date i want to display error message : "can make a date bigg than begin date".
[
'type' => 'calendar',
'name' => 'begindate',
'options' => [
'label' => 'begin date">*</span>',
'label_options' => ['disable_html_escape' => true],
],
'attributes' => [
'data-scvalidators' => 'Required',
'data-required-msg' => 'make the begin date.',
'data-sc-submit' => '.sumbit',
],
],
[
'type' => 'calendar',
'name' => 'enddate',
'options' => [
'label' => 'END DATE',
],
],
The exemple image

How do I set template and labelOptions for Select2?

How to set my template and labelOptions in Select2 in Yii2? For a regular field, this can be done via field->labelOptions and field->template. And how to do it for Select2?
$form->field($model, 'test',[
'labelOptions' => ['style' => 'display:none !important;'],
'template' => '{label}{input}{error}'])
->radioButtonGroup($data, ['itemOptions' => ['class' => 'btn btn-default', 'style' => 'display:none !important;']
]); ?>
Select2, which is in question: https://demos.krajee.com/widget-details/select2
I asked the question himself and answered it himself, and even in the question itself. It was enough to do as in the example from the question - set field->template and field->label Options as needed:
$form->field($model, 'test', [
'template' => '{label}{input}{error}'
])->widget(Select2::classname(), [
'data' => $data,
'pluginOptions' => [
'allowClear' => true
],
]);

Yii2 how add a new action button in grid [duplicate]

This question already has answers here:
Extend GridView ActionColumn with additional icon
(3 answers)
Closed 7 years ago.
I have following grid.
$gridColumns = [
'class'=>'kartik\grid\ActionColumn',
'headerOptions'=>['class'=>'kartik-sheet-style'],
'template' => '{delete}{my_button}',
],
echo GridView::widget([
'dataProvider'=> $dataProvider,
'columns' => $gridColumns,
'filterModel' => $filterModel,
],
]);
I want add to template a new action button for example {my_button}.
You should simply add a buttons param to your column, e.g. :
'template' => '{my_button}',
'buttons' => [
'my_button' => function ($url, $model, $key) {
return Html::a('My Action', ['my-action', 'id'=>$model->id]);
},
]
Read more : http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$buttons-detail

How i do custom Yii2 gridview sort?

How can I sort with a customized gridview header?
Please give the difference between label and header in the Yii2 gridview widget dataprovider.
Here is my code:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'class' => 'yii\grid\DataColumn',
'value' => function ($data) {
return $data->myTitle;
},
'headerOptions' => ['style'=>'text-align:center'],
'header' => 'Page Title',
'label' => 'Title'
],
]); ?>
Do header and label perform the same function?
How can I perform sorting in $data->myTitle?
Here my Output Screen:
I want Page Title, Status, Date Modified should be active.
Thanks in advance.
Found the answer.
Please add attributes to ActiveDataProvider in your Search Model.
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 5,
],
'sort' => ['attributes' => ['myTitle']],
]);
Add the attribute option in widget:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[
'class' => 'yii\grid\DataColumn',
'value' => function ($data) {
return $data->myTitle;
},
'headerOptions' => ['style'=>'text-align:center'],
'attribute' => 'myTitle',
'label' => 'Page Title'
],
]); ?>
Since myTitle is a field from the database and not a custom value, you can just use attribute. The rest may be unnecessary e.g the default class is DataColumn
'columns' => [
[
'attribute' => 'myTitle',
'label' => 'Label',
]
I am not very sure I understand your question, but sorting option can be included in your modelsearch.php. So in your case you have to do like this.
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> ['defaultOrder' => ['your_column'=>SORT_ASC]]
]);
if myTitle is a field in the database, why you are using such a long syntax. Just
'Columns'=>[
..
'myTitle',
..
],
should work fine and should be active for sorting as you want
if you want a different header/label for the column, use label instead of header as header is only a cell content and cannot be used for sorting, while label can. details
[
..
'attribute'=>'myTitle',
'label' => 'Page Title'
..
],

Setting the template property on Yii2 GridView / ActionColumn?

First ... old school, rusty Pascal/Clipper/VB developer trying to learn PHP and Yii2 at the same time.
Looking at http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$template-detail I should be able to easily remove the update and delete buttons in the ActionColumn ... I just don't know how / where to set the property.
Our GridView code is:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'last_name',
'first_name',
'email1:email',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
My gut tells me it's something to do with instantiating the ActionColumn class before we throw that in as a column ... but I've combed the forums and documentation and just can't find any example.
You are searching for the template properly. http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$template-detail
your column should be
[
'class' => 'yii\grid\ActionColumn',
'template' => "{view}",
],

Categories