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

Saturday, March 19, 2022

[FIXED] Yii2 add glyphicon into dataColumn

 March 19, 2022     php, yii, yii2     No comments   

Issue

[
        'class'=>'\kartik\grid\DataColumn',
        'attribute'=>'bumi_status',
        'value'=>function($model,$url){
            if($model->bumi_status == 'Bumi')
            {
                //return 'Yes';
                return '<span class="glyphicon glyphicon-ok"></span>';
            }
            else
            {
                return '<span class="glyphicon glyphicon-remove"></span>';
            }
        }
    ],

I would like to return a glyhpicon instead of word inside the column but now it showing the full sentence. Anyway how to make it show the icon?


Solution

You just need to add: 'format' => 'raw':

[
    'class'=>'\kartik\grid\DataColumn',
    'attribute'=>'bumi_status',
    'format' => 'raw',
    'value'=>function($model,$url){
        if($model->bumi_status == 'Bumi')
        {
            //return 'Yes';
            return '<span class="glyphicon glyphicon-ok"></span>';
        }
        else
        {
            return '<span class="glyphicon glyphicon-remove"></span>';
        }
    }
],

As described in the docs:

In which format should the value of each data model be displayed as (e.g. "raw", "text", "html", ['date', 'php:Y-m-d']). Supported formats are determined by the formatter used by the yii\grid\GridView. Default format is "text" which will format the value as an HTML-encoded plain text when yii\i18n\Formatter is used as the formatter of the GridView.

The default is text so Yii format it as HTML-encoded, and it formats the value. If the format is raw it just display the value as is.



Answered By - Ziki
  • 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