PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] How can I use a simple Dropdown list with filtering in the search box of GridView::widget, Yii2?

 March 08, 2022     gridview, php, yii, yii2, yii2-advanced-app     No comments   

Issue

I have two tables "attendance" with attributes id, status, date and "staff". staff_id is used as foreign key in attendance table. In _form.php of attendance I used

<?= $form->field($model, 'status')->dropDownList([ 'Present' => 'Present', 'Absent' => 'Absent', 'Leave' => 'Leave',], ['prompt' => 'Select status']) ?> 

for dropdown. Now I want to a dropdown in gridview search columns with property of filtering and searching. I would like my gridview to be filtered by the dropdown list I have. So when I choose a value from the dropdown list, it should search on base of choosed value. Any help would be highly appriciated.


Solution

I think your question is about status field

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        ........
        [
           'attribute' => 'status',
           'label' => 'Status',
           'filter' => [ 'Present' => 'Present', 'Absent' => 'Absent', 'Leave' => 'Leave',]
        ],
        ......


Answered By - ScaisEdge
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing