I made a custom column in sales_order_invoice_grid to display some additional data. This works fine but when clicking on the given column it does not react on any sorting mechanism like descending and ascending
Here is what I got
sales_order_invoice_grid
<column name="order_state" class="Foobar\InvoiceOrderStatus\Ui\Component\Listing\Column\Status">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="label" xsi:type="string" translate="true">Order Status</item>
</item>
</argument>
</column>
The corresponding class
class Status extends Column
{
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$orderId = $item["order_id"];
if (empty($orderId)) {
$item[$this->getData('name')] = "unkown";
continue;
}
/** @var \Magento\Sales\Model\OrderRepository $orderRepo */
$orderRepo = $objectManager->get('Magento\Sales\Model\OrderRepository');
/** @var \Magento\Sales\Model\Order $order */
$order = $orderRepo->get($orderId);
$item[$this->getData('name')] = $order->getStatus();
}
}
return $dataSource;
}
}
How can I apply descending / ascending sorting to my custom column?
asked Apr 27, 2017 at 6:19
xhallix
7022 gold badges8 silver badges27 bronze badges
-
Your question is very similar to this question and I hope this will help you out.P Pang– P Pang2017年04月28日 12:19:50 +00:00Commented Apr 28, 2017 at 12:19
-
In my case I modified the ui_component/sales_order_invoice_grid.xml is there something similar?xhallix– xhallix2017年04月30日 17:30:28 +00:00Commented Apr 30, 2017 at 17:30
1 Answer 1
<column name="order_state" class="Foobar\InvoiceOrderStatus\Ui\Component\Listing\Column\Status">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">desc</item>
<item name="label" xsi:type="string" translate="true">Order Status</item>
</item>
</argument>
</column>
You just need to add asc or desc sorting tab
<item name="sorting" xsi:type="string">desc</item>
answered May 1, 2017 at 8:41
Prince Patel
23.1k10 gold badges102 silver badges124 bronze badges
default