Hello Everyone,
In this blog, we will learn how to Set the Order Status Column Color In the Sales Order grid in Magento 2.
There are order statuses like pending, canceled, on hold, processing, etc.
We add different background colors for different order statuses.
Without wasting your time, let us guide you straight away. Follow the easy step given below to Set The Order Status Column Color in Magento 2.
STEPS FOR SET ORDER STATUS COLUMN BACKGROUND COLOR IN MAGENTO 2
Step 1: Create sales_order_grid.xml file
app/code/Vendor/Extension/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_columns">
<column name="status" component="Vendor_Extension/js/grid/columns/option">
<settings>
<filter>select</filter>
<options class="Magento\Sales\Ui\Component\Listing\Column\Status\Options"/>
<dataType>select</dataType>
<label translate="true">Status</label>
</settings>
</column>
</columns>
</listing>
Step 2: Create sales_order_index.xml file
app/code/Vendor/Extension/view/adminhtml/layout/sales_order_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="styles"/>
<head>
<css src="Vendor_Extension::css/orderstatus.css" />
</head>
<body>
<referenceContainer name="content">
<uiComponent name="sales_order_grid"/>
</referenceContainer>
</body>
</page>
Step 3: Create option.js file
app/code/Vendor/Extension/view/adminhtml/web/js/grid/columns/option.js
define([
'underscore',
'Magento_Ui/js/grid/columns/select'
], function (_, Column) {
'use strict';
return Column.extend({
defaults: {
bodyTmpl: 'Vendor_Extension/ui/grid/cells/text'
},
getOrderStatusColor: function (row) {
if (row.status == 'pending') {
return 'order-pending';
}else if(row.status == 'processing') {
return 'order-processing';
}else if(row.status == 'complete') {
return 'order-complete';
}else if(row.status == 'closed') {
return 'order-closed';
}else if(row.status == 'canceled') {
return 'order-canceled';
}
return '#303030';
}
});
});
Step 4: Create text.html file
app/code/Vendor/Extension/view/adminhtml/web/template/ui/grid/cells/text.html
<div class="data-grid-cell-content" data-bind="attr: { class: $col.getOrderStatusColor($row())}" text="$col.getLabel($row())"/>
Step 5: Create orderstatus.css file
app/code/Vendor/Extension/view/adminhtml/web/css/orderstatus.css
.order-pending {
background: #FFB347 none repeat scroll 0 0;
border: 1px solid #eb5202;
color: #eb5202;
}
.order-processing {
background: #E5F7FE none repeat scroll 0 0;
border: 1px solid #006bb4;
color: #006bb4;
}
.order-complete {
background: #d0e5a9 none repeat scroll 0 0;
border: 1px solid #5b8116;
color: #185b00;
}
.order-closed {
background: #f9d4d4 none repeat scroll 0 0;
border: 1px solid #e22626;
color: #e22626;
}
.order-canceled {
background: #f9d4d469 none repeat scroll 0 0;
border: 1px solid #e22626;
color: #71e226;
}
Change css as per your need.
Step 6: Finally run the below commands
$ php bin/magento setup:upgrade
$ php bin/magento setup:static-content:deploy -f
$ php bin/magento cache: clean
$ php bin/magento cache: flush
Step 7: Output:
Final Thoughts:
So this was the easiest way which we have told you in this blog. This is how you can Set The Order Status Background Color in Magento 2. Hope you liked the blog.
So quickly go to the comment box and tell me how you like this blog.
Stay tuned with us on our site to get new updates on Magento.
Thanks for reading and visiting our site.
