I have created custom column in Sales -> Order UI Grid. I have added "Profit" column. Which is not related to any database table and not the attribute. This column display just calculation of profit.
The issue is I can not sort the column. Column is sortable but it is sorting incorrectly.
I have checked many similar question in stack but nothing helpfull. As the column is not in table and not the attribute.
Following is my override file.
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="total_paid" class="Company\Module\Ui\Component\Listing\Column\PurchasedPrice">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Profit</item>
<item name="sortOrder" xsi:type="number">13</item>
</item>
</argument>
</column>
</columns>
</listing>
-
Please check my answer in this post. Hope it may help anyone.Gaurav Agrawal– Gaurav Agrawal2021年09月05日 06:34:58 +00:00Commented Sep 5, 2021 at 6:34
2 Answers 2
Maybe this is already old question, but it can be helpful for someone like me facing this issue.
According to this Magento 2 GitHub issue there is a ui_bookmark table in which some settings about ui_components (and Grid in my case) are stored.
Truncating this table and clearing the cache in my case fixed the problem of columns sortOrder in Grid.
I have faced this problem and below link helped me to get through it. Please follow the link provided below to add sorting and filtering of custom column in grid:
-
Thanks but as I mentioned the column is not in any table. The data of the column is coming from on block where I calculate the profit and return the profit amount. So this link is not useful.David Coder– David Coder2018年08月22日 11:38:16 +00:00Commented Aug 22, 2018 at 11:38
-
@DavidCoder Did you ever find an answer to your question ?Badong– Badong2021年04月14日 07:15:26 +00:00Commented Apr 14, 2021 at 7:15