Bootstrap Labels In Cgridview?

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.

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])',

            ),