1

I'm getting data in Grid in Ascending Order But I want this data in Descending order how can I set this??? My mycode_listing.xml is

<?xml version="1.0" encoding="UTF-8"?>

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
   <argument name="data" xsi:type="array">
       <item name="js_config" xsi:type="array">
           <item name="provider" xsi:type="string">makeanoffer_listing.makeanoffer_listing_data_source</item>
           <item name="deps" xsi:type="string">makeanoffer_listing.makeanoffer_listing_data_source</item>
       </item>
       <item name="spinner" xsi:type="string">makeanoffer_index_columns</item>
       <item name="buttons" xsi:type="array">
           <item name="add" xsi:type="array">
               <!-- <item name="name" xsi:type="string">add</item>
               <item name="label" xsi:type="string" translate="true">Add New Blog Post</item>
               <item name="class" xsi:type="string">primary</item>
               <item name="url" xsi:type="string">*/*/new</item> -->
           </item>
       </item>
   </argument>
   <dataSource name="makeanoffer_listing_data_source">
       <argument name="dataProvider" xsi:type="configurableObject">
           <argument name="class" xsi:type="string">makeanofferGridDataProvider</argument>
           <argument name="name" xsi:type="string">makeanoffer_listing_data_source</argument>
           <argument name="primaryFieldName" xsi:type="string">makeanoffer_id</argument>
           <argument name="requestFieldName" xsi:type="string">id</argument>
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
               <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                   <item name="update_url" xsi:type="url" path="mui/index/render"/>
               </item>
           </argument>
       </argument>
   </dataSource>
   <listingToolbar name="listing_top">
       <argument name="data" xsi:type="array">
           <item name="config" xsi:type="array">
               <item name="sticky" xsi:type="boolean">true</item>
           </item>
       </argument>
       <bookmark name="bookmarks"/>
       <columnsControls name="columns_controls"/>
       <filterSearch name="fulltext"/> <!--yha pr side wala jha pr full name likhna hoga -->
       <filters name="listing_filters">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="columnsProvider" xsi:type="string">makeanoffer_listing.makeanoffer_listing.makeanoffer_index_columns</item>
                   <item name="storageConfig" xsi:type="array">
                       <item name="provider" xsi:type="string">storageConfig.storageConfig.listing_top.bookmarks</item>
                       <item name="namespace" xsi:type="string">current.filters</item>
                   </item>
                   <item name="templates" xsi:type="array">
                       <item name="filters" xsi:type="array"> <!--ye wo 2ra wala filter side me ha conform ni ha... whi ha Q k nechy nam b likha ha items ka -->
                           <item name="select" xsi:type="array">
                               <item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
                               <item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
                           </item>
                       </item>
                   </item>
                   <item name="childDefaults" xsi:type="array">
                       <item name="provider" xsi:type="string">storageConfig.storageConfig.listing_top.listing_filters</item>
                       <item name="imports" xsi:type="array">
                           <item name="visible" xsi:type="string">storageConfig.storageConfig.makeanoffer_index_columns.${ $.index }:visible</item>
                       </item>
                   </item>
               </item>
               <item name="observers" xsi:type="array">
                   <item name="column" xsi:type="string">column</item>
               </item>
           </argument>
       </filters>
       <massaction name="listing_massaction">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="selectProvider" xsi:type="string">makeanoffer_listing.makeanoffer_listing.makeanoffer_index_columns.ids</item>
                   <item name="indexField" xsi:type="string">makeanoffer_id</item>
               </item>
           </argument>
           <action name="delete">
               <argument name="data" xsi:type="array">
                   <item name="config" xsi:type="array">
                       <item name="type" xsi:type="string">delete</item>
                       <item name="label" xsi:type="string" translate="true">Delete</item>
                       <item name="url" xsi:type="url" path="makeanoffer/index/massDelete"/>
                       <item name="confirm" xsi:type="array">
                           <item name="title" xsi:type="string" translate="true">Delete items</item>
                           <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                       </item>
                   </item>
               </argument>
           </action>
       </massaction>
       <paging name="listing_paging"/>
   </listingToolbar>

   <columns name="makeanoffer_index_columns">
       <argument name="data" xsi:type="array">
           <item name="config" xsi:type="array">
               <item name="storageConfig" xsi:type="array">
                   <item name="provider" xsi:type="string">makeanoffer_listing.makeanoffer_listing.listing_top.bookmarks</item>
                   <item name="namespace" xsi:type="string">current</item>
               </item>
               <item name="editorConfig" xsi:type="array">
                   <item name="selectProvider" xsi:type="string">makeanoffer_listing.makeanoffer_listing.makeanoffer_index_columns.ids</item>
                   <item name="enabled" xsi:type="boolean">true</item>
                   <item name="indexField" xsi:type="string">id</item>
                   <item name="clientConfig" xsi:type="array">
                       <item name="saveUrl" xsi:type="url" path="news/index/inlineEdit"/>
                       <item name="validateBeforeSave" xsi:type="boolean">false</item>
                   </item>
               </item>
               <item name="childDefaults" xsi:type="array">
                   <item name="fieldAction" xsi:type="array">
                       <item name="provider" xsi:type="string">makeanoffer_listing.makeanoffer_listing.makeanoffer_index_columns_editor</item>
                       <item name="target" xsi:type="string">startEdit</item>
                       <item name="params" xsi:type="array">
                           <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                           <item name="1" xsi:type="boolean">true</item>
                       </item>
                   </item>
                   <item name="storageConfig" xsi:type="array">
                       <item name="provider" xsi:type="string">makeanoffer_listing.makeanoffer_listing.listing_top.bookmarks</item>
                       <item name="root" xsi:type="string">columns.${ $.index }</item>
                       <item name="namespace" xsi:type="string">current.${ $.storageConfig.root}</item>
                   </item>
               </item>
           </item>
       </argument>
       <selectionsColumn name="ids">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="resizeEnabled" xsi:type="boolean">false</item>
                   <item name="resizeDefaultWidth" xsi:type="string">55</item>
                   <item name="indexField" xsi:type="string">makeanoffer_id</item>
               </item>
           </argument>
       </selectionsColumn>
       <column name="name">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="filter" xsi:type="string">text</item>
                   <item name="editor" xsi:type="array">
                       <item name="editorType" xsi:type="string">text</item>
                       <item name="validation" xsi:type="array">
                           <item name="required-entry" xsi:type="boolean">true</item>
                       </item>
                   </item>
                   <item name="label" xsi:type="string" translate="true">Name</item>
               </item>
           </argument>
       </column>
       <column name="email">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="editor" xsi:type="array">
                       <item name="editorType" xsi:type="string">textarea</item>
                       <item name="validation" xsi:type="array">
                           <item name="required-entry" xsi:type="boolean">true</item>
                       </item>
                   </item>
                   <item name="label" xsi:type="string" translate="true">Email</item>
               </item>
           </argument>
       </column>   
       <column name="pnumber">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="editor" xsi:type="array">
                       <item name="editorType" xsi:type="string">textarea</item>
                       <item name="validation" xsi:type="array">
                           <item name="required-entry" xsi:type="boolean">true</item>
                       </item>
                   </item>
                   <item name="label" xsi:type="string" translate="true">Phone Number</item>
               </item>
           </argument>
       </column>   
1

To display admin grid data in descending order to your custom module follow the Magento_Sales Because of Magento sales module display order data in descending order.

vendor/magento/module-sales/view/adminhtml/ui_component/sales_order_grid.xml

Find below code

<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
        <settings>
            <filter>dateRange</filter>
            <dataType>date</dataType>
            <label translate="true">Purchase Date</label>
            <sorting>desc</sorting>
        </settings>
    </column>

Magento sales order sorting data descending order ad Created_date see in above code. you can set sort order By ID, By Date etc...

I hope it helps!

0
<column name="name">
           <argument name="data" xsi:type="array">
               <item name="config" xsi:type="array">
                   <item name="filter" xsi:type="string">text</item>
                   <item name="sorting" xsi:type="string">desc</item>
                   <item name="editor" xsi:type="array">
                       <item name="editorType" xsi:type="string">text</item>
                       <item name="validation" xsi:type="array">
                           <item name="required-entry" xsi:type="boolean">true</item>
                       </item>
                   </item>
                   <item name="label" xsi:type="string" translate="true">Name</item>
               </item>
           </argument>
</column>   

You just need to add asc or desc sorting tab

<item name="sorting" xsi:type="string">desc</item>
  • Where I need to add This??? can you please mention in above code??? I tried this earlier in every single column but it was not working for me – Asad Khan Mar 28 at 10:35
  • check updated answer – Rk Rathod Mar 28 at 10:39
  • Did I need to add this in every single column??? – Asad Khan Mar 28 at 10:40
  • I am Not Sure but yes try this – Rk Rathod Mar 28 at 10:40
  • Its not working – Asad Khan Mar 28 at 10:48

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.