想要根据表中的字段显示CGridview,并在显示中区分它们


Want to display CGridview based on a field in table and distinguish them in display?

我有CGridview,它由消息列表组成,我想通过网格中的颜色变化来区分它的已读和未读,我不擅长CSS,所以我对此一无所知?

  1. 插件main.css

    .grid-view table.items tr.unread {
        background: none repeat scroll 0 0 #FF0000 !important; /* red color is unread */
     }
    .grid-view table.items tr.read {
        background: none repeat scroll 0 0 #00FF00 !important; /* green color is read */
    }
    
  2. 在消息模型中

    function isRead()
    {
        return $this->hasRead;
    }
    
  3. 在CGridView中添加行css类表达式

    'rowCssClassExpression' => '$data->isRead()?"read":"unread"',