1

I created a custom admin grid using a lising uicomponent. I want the initial sort order to sort by 2 columns. This does the trick in the grid's Collection class for the initial page load of the grid:

protected function _initSelect()
{
    parent::_initSelect();

    $this->setOrder('zone_name', 'asc');
    $this->setOrder('zip', 'asc');

    return $this;
}

However, if you then sort the column in the admin by clicking any column header, it always maintains the above sorting.

I found that if instead of doing the above, I can set the default sort order in the listing uicomponents XML file like this:

<column name="zone_name">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">Zone</item>
            <item name="sorting" xsi:type="string">asc</item>
        </item>
    </argument>
</column>

The key line there is:

<item name="sorting" xsi:type="string">asc</item>

That works fine, but is there a way to use that method and also sort by two columns?

Your Answer

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

Browse other questions tagged or ask your own question.