I have a custom grid which has parent_company_id stored in its table, and in the grid list I have displayed parent_company_name by using join the current table with company table using the ID.

When I click on the parent_company_id grid column, it is sorting the values based on ID in ascending and descending order. Please see the image for better clarification, Here the word starting with D comes before A because it is sorting by ID.

<column name="parent_company_id">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Test\Test1\Model\Source\Subcompany\ParentCompanyList</item>
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">select</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
                    <item name="dataType" xsi:type="string">select</item>
                    <item name="label" xsi:type="string" translate="true">Parent Company Name</item>                    
                    <item name="sortOrder" xsi:type="number">20</item>
                </item>
            </argument>
        </column>

Test\Test1\Model\Source\Subcompany\ParentCompanyList.php

public function toOptionArray()
    {
        $activeCompanyList = $this->helper->getAllCompany();
        $ListOptions[] = [
            'value' => "",
            'label' => 'Please Select'
        ];
        foreach ($activeCompanyList as $list) {
            $ListOptions[] = [
                'value' => $list['id'],
                'label' => $list['name']
            ];
        }
        return $ListOptions;
    }

I have tried to join the table in Collection. But its not worked.

protected function _initSelect()
     {
        parent::_initSelect();
        $this->company_table = $this->getTable("tbl_company");
        $this->getSelect()
            ->join(array('company' =>$this->company_table), $this->main_table . 'parent_company_id= company.id',
            array('*')
        );

Also tried giving name instead of id as value in the toOptionArray(). doesnot worked because the array then become associate array,

Any idea how can I sort by alphabetical order here?

Thank you.

0

There are 0 best solutions below