Magento, different background color for group of rows on backend grid

后端 未结 3 1577
小蘑菇
小蘑菇 2020-12-22 04:34

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 kn

3条回答
  •  情书的邮戳
    2020-12-22 05:12

    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.

    getData($this->getColumn()->getIndex());
            return '
    '.$value.'
    '; } } ?>

    And the result:

    Screen shot of grid with rendered column

提交回复
热议问题