Magento,后端网格上的一组行的不同背景颜色 [英] Magento, different background color for group of rows on backend grid

查看:183
本文介绍了Magento,后端网格上的一组行的不同背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有网格的后台管理页面上,我需要更改组的行的背景颜色。不是按行逐行替换颜色作为默认值,而是根据已知的列值着色组。



我正在研究这个SO问题:。有一些SO问题也有助于理解解决方案。



我没有设法改变最初想要的整行背景颜色,我只是修改了细胞背景。但最后,足以指出用户这一行有所不同。我所做的是添加一个新的自定义列。在渲染器属性中,我引用了一个新类。

  $ this- > addColumn('collision_type',array(
'header'=> $ helper-> __('Collision'),
'align'=>'center',
'index'=>'collision_type',
'type'=>'action',
'renderer'=> new Dts_Banners_Block_Adminhtml_Collisions_Grid_Renderer_Collisiontype(),
));

我将所需的类放入新的子树中:

 网格
└─渲染器
└─Collisiontype.php

这是应该呈现列的新类。为了让不同的颜色只需要评估 $ value 变量并为相应的值应用不同的颜色样式,那就是我现在正在做的。

 <?php 
class Dts_Banners_Block_Adminhtml_Collisions_Grid_Renderer_Collisiontype extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $ row){
$ value = $ row-> getData($ this-> getColumn() - > getIndex());
return'< div style =color:#FFF; font-weight:bold; background:#F55804; border-radius:8px; width:100%>'。$ value。'< DIV>';
}
}
?>

结果:


On a backend admin page with a grid I need to change the background color for groups of rows. Not alternate color row by row as default but coloring groups according to a known column value.

I was looking into this SO question: Approach on changing row color on orders grid in admin and other similar pages. But can't reproduce what I need as this question refers to a value in a column that will be repeated.

I need to either use different colors for different groups or at least use alternate colors of those groups.

Maybe something like this:

解决方案

For anyone looking for a solution. I used this tutorial on the Inchoo website: Add custom renderer for a custom column in Magento grid. There are some SO questions that also helped to understand the solution.

I didn't manage to change the full row background color as initially wanted, I'm just modifying the cell background. But at the end, is enough to point the user that this row is somewhat different. What I have done was add a new custom column. On the renderer property I referenced a new class.

$this->addColumn('collision_type', array(
          'header'  => $helper->__('Collision'),
          'align'   => 'center',
          'index'   => 'collision_type',
          'type'    => 'action',
          'renderer'=> new Dts_Banners_Block_Adminhtml_Collisions_Grid_Renderer_Collisiontype(),
));

I placed the needed class inside a new subtree:

Grid
  └─ Renderer
        └─ Collisiontype.php

And this is the new class that should render the column. To have different colors just need to evaluate the $value variable and apply different color styles for the corresponding value, that is what I'm doing now.

<?php
class Dts_Banners_Block_Adminhtml_Collisions_Grid_Renderer_Collisiontype extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row) {
        $value =  $row->getData($this->getColumn()->getIndex());
        return '<div style="color:#FFF;font-weight:bold;background:#F55804;border-radius:8px;width:100%">'.$value.'</div>';
    }
}
?>

And the result:

这篇关于Magento,后端网格上的一组行的不同背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆