2

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
2
  • Your question is very similar to this question and I hope this will help you out. Commented Apr 28, 2017 at 12:19
  • In my case I modified the ui_component/sales_order_invoice_grid.xml is there something similar? Commented Apr 30, 2017 at 17:30

1 Answer 1

4
+25
<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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.