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 Answer 1

2

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>
2
  • it works, How do I add a filter for the column "SKU" in Reports Grid
    – Jaisa
    Commented Oct 18, 2021 at 5:02
  • Hi @Jaisa I don't currently have a local environment to reference, but here is an article that shows how to add a filter: amasty.com/knowledge-base/…
    – Logan
    Commented Oct 19, 2021 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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