0

I'm using the sales_order collection. Now I was able to display it in my grid custom admin page. But I want the result to display in descending order. So meaning the latest order should be displayed at the top portion. But eventhough I added the sortOrder still no luck. Am I missing something? Below is my Grid code

enter image description here entity_id asc 0 text ID text Customer Email

            </item>
        </argument>
    </column>
    <column name="customer_firstname">
       <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">First Name</item>

           </item>
       </argument>
    </column>
    <column name="customer_lastname">
       <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">Last Name</item>

           </item>
       </argument>
    </column>
    <column name="customer_middlename">
       <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">Middle Name</item>

           </item>
       </argument>
    </column>
    <column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" >
       <argument name="data" xsi:type="array">
           <item name="config" xsi:type="array">
               <item name="filter" xsi:type="string">dateRange</item>
               <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
               <item name="dataType" xsi:type="string">date</item>
               <item name="label" xsi:type="string" translate="true">Order Date</item>
                <item name="sorting" xsi:type="string">desc</item>
                <item name="sortOrder" xsi:type="number">1</item>
           </item>
       </argument>
   </column>

I already cleared my cache and all but it's not taking effect. Also I want the Order Date be displayed at the very first column

2
  • Add sortOrder for all the columns in grid to make in work..You have added sort order for only 1 coulmn
    – aravind
    Mar 9, 2020 at 6:59
  • @aravind thanks I already fixed this issue. It was because of the ui_bookmark table. It's not updating the value. When I deleted that row I was able to see the updated grid table Mar 9, 2020 at 7:02

1 Answer 1

0

Follow this link click here

change this Function

public function _beforeLoad()
{
    parent::_beforeLoad();
    $this->setOrder('your_column_name', 'DESC');
    return $this;
}

Your Answer

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

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