Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento,后端网格上一组行的不同背景色_Magento_Grid_Magento 1.7 - Fatal编程技术网

Magento,后端网格上一组行的不同背景色

Magento,后端网格上一组行的不同背景色,magento,grid,magento-1.7,Magento,Grid,Magento 1.7,在带有网格的后端管理页面上,我需要更改行组的背景颜色。默认情况下,不是逐行交替使用颜色,而是根据已知列值对组进行着色 我正在研究这个问题:和其他类似的页面。但无法重现我需要的内容,因为这个问题指的是将重复的列中的值 我需要为不同的组使用不同的颜色,或者至少使用这些组的其他颜色 也许是这样的: 适用于任何寻求解决方案的人。我在Inchoo网站上使用了此教程:。有些问题也有助于理解解决方案 我没有按照最初的要求更改整行背景颜色,我只是修改了单元格背景。但在最后,这足以向用户指出这一行有所不同。我所做

在带有网格的后端管理页面上,我需要更改行组的背景颜色。默认情况下,不是逐行交替使用颜色,而是根据已知列值对组进行着色

我正在研究这个问题:和其他类似的页面。但无法重现我需要的内容,因为这个问题指的是将重复的列中的值

我需要为不同的组使用不同的颜色,或者至少使用这些组的其他颜色

也许是这样的:


适用于任何寻求解决方案的人。我在Inchoo网站上使用了此教程:。有些问题也有助于理解解决方案

我没有按照最初的要求更改整行背景颜色,我只是修改了单元格背景。但在最后,这足以向用户指出这一行有所不同。我所做的是添加一个新的自定义列。在
renderer
属性上,我引用了一个新类

$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(),
));
我将所需的类放置在一个新的子树中:

Grid
  └─ Renderer
        └─ 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>';
    }
}
?>

结果是:


适用于任何寻求解决方案的人。我在Inchoo网站上使用了此教程:。有些问题也有助于理解解决方案

我没有按照最初的要求更改整行背景颜色,我只是修改了单元格背景。但在最后,这足以向用户指出这一行有所不同。我所做的是添加一个新的自定义列。在
renderer
属性上,我引用了一个新类

$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(),
));
我将所需的类放置在一个新的子树中:

Grid
  └─ Renderer
        └─ 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>';
    }
}
?>

结果是:


在我的例子中,我使用了上面的代码片段。我需要在网格中为类别创建一个自定义广播列。所以我把所有的条件都放在这里

public function render(Varien_Object $row) {
        $category = Mage::registry('current_category');
        $screenId = $category->getCategoryAttachedID();
        if($row->getId()==$screenId)$checked='checked="checked"';
        else $checked='';
        return '<input type="radio" name="screen_id" value="'.$row->getId().'" '.$checked.' >';
    }
公共函数渲染(Varien_对象$row){
$category=Mage::注册表('current_category');
$screenId=$category->GetCategoryAtacheDid();
如果($row->getId()=$screenId)$checked='checked='checked';
否则$checked='';
返回“”;
}

在我的例子中,我使用了上面的代码片段。我需要在网格中为类别创建一个自定义广播列。所以我把所有的条件都放在这里

public function render(Varien_Object $row) {
        $category = Mage::registry('current_category');
        $screenId = $category->getCategoryAttachedID();
        if($row->getId()==$screenId)$checked='checked="checked"';
        else $checked='';
        return '<input type="radio" name="screen_id" value="'.$row->getId().'" '.$checked.' >';
    }
公共函数渲染(Varien_对象$row){
$category=Mage::注册表('current_category');
$screenId=$category->GetCategoryAtacheDid();
如果($row->getId()=$screenId)$checked='checked='checked';
否则$checked='';
返回“”;
}

上面的答案很好,但有时您希望在不创建新文件的情况下执行相同的操作。
下面是另一种方法,可以实现保留在网格文件中的相同结果

$this->addColumn('collision_type', array(
      'header'  => $helper->__('Collision'),
      'align'   => 'center',
      'index'   => 'collision_type',
      'type'    => 'action',
      'frame_callback' => [$this, '_formatCell']
));
然后在同一个文件中

public function _formatCell($value, Varien_Object $row, Mage_Adminhtml_Block_Widget_Grid_Column $column)
{
    $value =  $row->getData($column->getIndex());
    return '<div style="color:#FFF;font-weight:bold;background:#F55804;border-radius:8px;width:100%">'.$value.'</div>';
}
public function\u formatCell($value,Varien\u Object$行,Mage\u Adminhtml\u Block\u Widget\u Grid\u Column$列)
{
$value=$row->getData($column->getIndex());
返回“.$value.”;
}

上面的答案很好,但有时您希望在不创建新文件的情况下执行相同的操作。
下面是另一种方法,可以实现保留在网格文件中的相同结果

$this->addColumn('collision_type', array(
      'header'  => $helper->__('Collision'),
      'align'   => 'center',
      'index'   => 'collision_type',
      'type'    => 'action',
      'frame_callback' => [$this, '_formatCell']
));
然后在同一个文件中

public function _formatCell($value, Varien_Object $row, Mage_Adminhtml_Block_Widget_Grid_Column $column)
{
    $value =  $row->getData($column->getIndex());
    return '<div style="color:#FFF;font-weight:bold;background:#F55804;border-radius:8px;width:100%">'.$value.'</div>';
}
public function\u formatCell($value,Varien\u Object$行,Mage\u Adminhtml\u Block\u Widget\u Grid\u Column$列)
{
$value=$row->getData($column->getIndex());
返回“.$value.”;
}

您想更改单元格的颜色还是整行的颜色?整组行都有一个值相同的列我不确定,我是否得到了它。您会添加一个带说明的图形,还是仅显示一个示例?谢谢。顺便说一句,我正在做一些类似的事情。这是我目前的进展:嗯,可能是这样的,我需要检查一下。所以我在我的问题上指的是试图解决一些问题,比如你在做什么。我将在周一尝试看看能做些什么。我将使用您的屏幕截图显示一个我想要的示例,对您来说可以吗?您想更改单元格的颜色还是整行的颜色?整组具有相同值的列的行我不确定,我是否得到了它。您会添加一个带说明的图形,还是仅显示一个示例?谢谢。顺便说一句,我正在做一些类似的事情。这是我目前的进展:嗯,可能是这样的,我需要检查一下。所以我在我的问题上指的是试图解决一些问题,比如你在做什么。我将在周一尝试看看能做些什么。我会用你的截图来展示一个我想要的例子,你觉得可以吗?