0

Magento Admin > Reports > Products > Ordered I have created new columns(SKU) using the help of these two links in the report grid.

Magento 2 ordered product report

HOW TO ADD COLUMN TO 'Order Total Report' GRID and display custom customer data to new column in magento 2?

app/code/Mymodule/Orderedproductsreport/view/adminhtml/layout/reports_report_product_sold_grid.xml

<referenceBlock name="adminhtml.report.grid.columnSet">
    <arguments>
        <argument name="id" xsi:type="string">report_product_sold</argument>
        <argument name="count_totals" xsi:type="string">1</argument>
    </arguments>
    <block class="Magento\Backend\Block\Widget\Grid\Column" name="adminhtml.report.grid.columnSet.sku" as="sku">
        <arguments>
            <argument name="header" xsi:type="string" translate="true">SKU-*1</argument>
            <argument name="sortable" xsi:type="string">1</argument>
            <argument name="type" xsi:type="string">text</argument>
            <argument name="index" xsi:type="string">order_items_sku</argument>
            <argument name="id" xsi:type="string">sku</argument>
            <argument name="column_css_class" xsi:type="string">col-sku</argument>
            <argument name="header_css_class" xsi:type="string">col-sku</argument>
        </arguments>
    </block>
    <block class="Magento\Backend\Block\Widget\Grid\Column" as="name">
        <arguments>
            <argument name="header" xsi:type="string" translate="true">Product-1</argument>
            <argument name="sortable" xsi:type="string">5</argument>
            <argument name="type" xsi:type="string">text</argument>
            <argument name="index" xsi:type="string">order_items_name</argument>
            <argument name="id" xsi:type="string">name</argument>
            <argument name="column_css_class" xsi:type="string">col-product</argument>
            <argument name="header_css_class" xsi:type="string">col-product</argument>
        </arguments>
    </block>
    <block class="Magento\Backend\Block\Widget\Grid\Column" as="ordered_qty">
        <arguments>
            <argument name="header" xsi:type="string" translate="true">Ordered Quantity-1</argument>
            <argument name="sortable" xsi:type="string">10</argument>
            <argument name="total" xsi:type="string">sum</argument>
            <argument name="type" xsi:type="string">number</argument>
            <argument name="index" xsi:type="string">ordered_qty</argument>
            <argument name="id" xsi:type="string">ordered_qty</argument>
            <argument name="column_css_class" xsi:type="string">col-qty</argument>
            <argument name="header_css_class" xsi:type="string">col-qty</argument>
        </arguments>
    </block>
</referenceBlock>

Product, Ordered Quantity these two columns are calling from core file while SKU is calling from my custom module file.

SKU column is showing after Product, Ordered Quantity column.

How can I move SKU before Product column?

Any help will be appreciated.

1

Hello @Jimit Bhavsar

These are layout XML files, so we should be able to utilize Layout Instructions on the block.

More specifically, you can use the before="adminhtml.report.grid.columnSet.name" attribute on your SKU column block:

<block class="Magento\Backend\Block\Widget\Grid\Column" name="adminhtml.report.grid.columnSet.sku" as="sku" before="adminhtml.report.grid.columnSet.name">
    <arguments>
        <argument name="header" xsi:type="string" translate="true">SKU</argument>
        <argument name="sortable" xsi:type="string">1</argument>
        <argument name="type" xsi:type="string">text</argument>
        <argument name="index" xsi:type="string">order_items_sku</argument>
        <argument name="id" xsi:type="string">sku</argument>
        <argument name="column_css_class" xsi:type="string">col-sku</argument>
        <argument name="header_css_class" xsi:type="string">col-sku</argument>
    </arguments>
</block>
| improve this answer | |

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.