Yii Framework Forum: Bootstrap Labels In Cgridview? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Bootstrap Labels In Cgridview? Rate Topic: -----

#1 User is offline   auren27 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 06-February 13

Posted 05 July 2013 - 03:18 AM

Hi all,

I was wondering if anyone out there has managed to get Bootstrap labels working on data in a CGridView data table?

What I am trying to do is add a span class to data in one of the columns and then show a certain label style depending on the data in the cell. For example:

<span class="label label-success">Open</span>
<span class="label label-important">Closed</span>
<span class="label label-success">Open</span>
<span class="label label-inverse">Dead</span>
<span class="label label-important">Closed</span>

I have used the following code to add a class to the cell:

            array(
                'name' => 'file_name',
                'header' => 'Filename',
                'filter' => '',
                'cssClassExpression' => '$data["approved"] == 1 ? "bold" : ""',
            ),


This works but only adds a class to the row.

Has anyone got any experience with this?

Many thanks in advance.
0

#2 User is offline   Pep 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 06-August 11

Posted 06 July 2013 - 10:40 PM

One thing you can do is create a method in your model to return the appropriate label and use it in the grid like this:

            array(
                'name' => 'file_name',
                'header' => 'Filename',
                'type'=>'raw',
                'value'=>'FileModel::getBootstrapLabel($data[approved])',
            ),

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users