0

I'm making a custom grid that shows the ID and the status of specific orders. It is currently like this:

grid

I wanna make column Order ID background color change, depending on Status column value. How can I make that?

This are both my renderers:

ID:

public function render(Varien_Object $row)
{
    $value =  $row->getData($this->getColumn()->getIndex());
    if ($value || !empty($value)) {
        return '<span style="font-size: 15px">'.$value.'</span>';
    }
}

and Status:

public function render(Varien_Object $row)
{
    $value =  $row->getData($this->getColumn()->getIndex());
    if ($value || !empty($value)) {
        if ($value == '1') {
            return '<div style="text-align: center;"><span style="font-size: 15px">' . $value . '</span></div>';
        } elseif ($value == '2') {
            return '<div style="background: limegreen; width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">' . $value . '</span></div>';
        } elseif ($value == '3') {
            return '<div style="background: green; width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">' . $value . '</span></div>';
        } elseif ($value == '4') {
            return '<div style="background: red; width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">' . $value . '</span></div>';
        }
    } else {
        return '<div style="width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">Sem Informações</div></span>';
    }
}
1

It sounds like you're not sure how to access the status property within the column renderer for the id property. Is that right?

If so, then you need only to understand what $row is: it is the [order] model you are working with on the current row. Therefore, even within your renderer for the id column, you can easily call $row->getStatus() in a conditional branch as you do with the status column renderer.

It might look like this (using your own code as sample):

public function renderIdColumn(Varien_Object $row)
{
    $status = $row->getStatus();
    $id = $row->getId();

    if ($status || !empty($status)) {
        if ($status == '1') {
            return '<div style="text-align: center;"><span style="font-size: 15px">' . $id . '</span></div>';
        } elseif ($status == '2') {
            return '<div style="background: limegreen; width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">' . $id . '</span></div>';
        } elseif ($status == '3') {
            return '<div style="background: green; width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">' . $id . '</span></div>';
        } elseif ($status == '4') {
            return '<div style="background: red; width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">' . $id . '</span></div>';
        }
    } else {
        return '<div style="width: 100%; padding: 1px; border-radius: 15px; text-align: center;"><span style="color: white; font-size: 15px">Sem Informações</div></span>';
    }
}
  • oooooh, thank you. Yes, I was quite confused about $row. It worked fine, thanks – Stordon Sep 21 '17 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.