1

I created my custom module with admin grid, then i tried to add order increment id to my custom grid by altering the grid collection with alias name.

The order id is displaying in grid. Now, if I try to filter by increment_id , then it throws an error. Without alias its working fine, if i add alias and try to filter at that time it throws the error.

Following is my code:

     <column name="order_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="filter_index" xsi:type="string">o.increment_id</item>
                    <item name="add_field" xsi:type="boolean">false</item>
                    <item name="label" xsi:type="string" translate="true">Order ID</item>
                    <item name="sortOrder" xsi:type="number">75</item>
                </item>
            </argument>
        </column>

app\code\Sugarcode\Test\Model\ResourceModel\Test\Grid\Collection.php

protected function _initSelect()
    {
         parent::_initSelect();
         $this->getSelect()->joinLeft(
            ['o' => 'sales_order_grid'],
            "(o.entity_id = main_table.id)",
            [
                'o.increment_id as order_id'
            ]
        );
    //$this->printLogQuery(true);
        return $this;
    }

So please tell how can I add the filter_index in magento2 with UI Component ?

6

I got it by using the addFiltertoMap

Which is defined in

app\code\Sugarcode\Test\Model\ResourceModel\Test\Grid\Collection.php

protected function _construct()
{
    parent::_construct();
    $this->addFilterToMap(
        'order_id',
        'o.increment_id'
    );
}
| improve this answer | |
1

Add this method into following class

app\code\Sugarcode\Test\Model\ResourceModel\Test\Grid\Collection.php
public function addFieldToFilter($field, $condition = null)
{
    if ($field === 'order_id') {
        // custom condition
        return;
    }

    return parent::addFieldToFilter($field, $condition);
}
| improve this answer | |
  • best way is addFilterToMap – Pradeep Kumar Nov 27 '15 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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