Magento – magento 2 html in ui component grid column

gridmagento2uicomponent

I want to add link to order in ui component grid for my custom logs table.

I was able to successfully split in lines log message with

       $item[$this->getData('name')] = html_entity_decode(nl2br($item[$this->getData('name')]));

but this approach does not work for anchors:

public function prepareDataSource(array $dataSource)
{
    if (isset($dataSource['data']['items'])) {
        foreach ($dataSource['data']['items'] as & $item) {
            if (array_key_exists('order_id', $item) && !empty($item['order_id'])) {
                try {
                    if ($order = $this->orderRepository->get($item['order_id'])) {
                        $url = $this->storeManager->getStore()->getUrl('sales/order/view', ['order_id' => $order->getEntityId()]);
                        $item[$this->getData('name')] = html_entity_decode("<a href=\"$url\">" . $order->getIncrementId() . "</a>");
                    }
                } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {

                }

            }


        }
    }

    return $dataSource;
}

in grid looks like http://i.imgur.com/aA86VlK.png

Is there a way to not escape html entities in the UI component grid?

Best Answer

    <column name="order" class="Vendor\OrderExport\Ui\Component\Listing\Column\VendorLog\OrderId">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
                <item name="label" xsi:type="string" translate="true">Order ID</item>
            </item>
        </argument>
    </column>

Setting body template for cell fixed issue: <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>