0

i want to change Status column - with color in CMS october in columns.yaml ...

how i add this :

<div class="control-list">
    <table class="table data">
        <thead>
            <tr>
                <th style="width: 150px"><span>Status</span></th>
                <th class="active sort-asc"><a href="/">Title</a></th>
            </tr>
        </thead>
        <tbody> 
            <tr>
                <td>
                    <span class="oc-icon-circle text-success">
                        Approved
                    </span>
                </td>
                <td>The sun is shining</td>
            </tr>
            <tr>
                <td>
                    <span class="oc-icon-circle text-danger">
                        Cancelled
                    </span>
                </td>
                <td>The weather is sweet here</td>
            </tr>
        </tbody>
    </table>
</div>

How can I add such a thing into my system model?

6
  • can you share what efforts did you make, we can guide you Sep 21, 2020 at 20:31
  • octobercms.com/docs/ui/list - like that in CMS october - Status column
    – almog19943
    Sep 22, 2020 at 5:39
  • try to use this -> octobercms.com/docs/backend/lists#column-partial Sep 22, 2020 at 7:49
  • i see it look good but how i can do that , i cant see that on database status: label: Status type: group conditions: status in (:filtered) options: pending: Pending active: Active closed: Closed
    – almog19943
    Sep 22, 2020 at 9:31
  • define your status values in your model as static variable hardcoded as they may be just like 4-5 status, and use them in partial to check it out Sep 22, 2020 at 9:48

1 Answer 1

1

Entire row (easier)

You can apply a class to the entire row overwriting listInjectRowClass in your controller and return the name of one of the classes listed in the docs, for example:

public function listInjectRowClass($model, $definition)
{
    switch ($model->status) {
        case Order::STATUS_NEW:
            return 'new';
            break;

        case Order::STATUS_PREPARING:
            return 'processing';
            break;

        case Order::STATUS_PREPARED:
            return 'processing';
            break;

        case Order::STATUS_SHIPPED:
            return 'frozen';
            break;

        case Order::STATUS_DELIVERED:
            return 'positive';
            break;

        case Order::STATUS_WITHDRAWN:
            return 'positive';
            break;
    }
}

This will result in something like this:

enter image description here

Just one column of the row

This is a little more tricky, basically you have to use a partial for rendering the column.

In your columns.yaml

content:
    type: partial
    path: ~/plugins/acme/blog/models/comments/_content_column.htm

And in the partial file _content_column.htm you need to have something like this:

<span class="<?= $record->column_status_class ?>">
   <?= $value ?>
</span>

where, as the docs say:

$value is the default cell value

$record is the model used for the cell

So, for this example, the model need a function called getColumnStatusClassAttribute which will return the proper class name.

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.