0

How to sort export csv file according to desc order by the creation time

<exportButton name="export_button"/>
 <exportButton name="export_button"/>
        <paging name="listing_paging"/>
    </listingToolbar>
    <columns name="thecoachsmb_blog_post_columns">
         <selectionsColumn name="ids">
            <settings>
                <indexField>customer_feedback_id</indexField>
                <resizeEnabled>false</resizeEnabled>
                <resizeDefaultWidth>55</resizeDefaultWidth>
                <visible>false</visible>
            </settings>
        </selectionsColumn> 
        <column name="post_id">
            <settings>
                <filter>textRange</filter>
                <label translate="true">ID</label>
                <sorting>desc</sorting>
            </settings>
        </column>
        <column name="title">
            <settings>
                <filter>text</filter>
                <editor>
                    <validation>
                        <rule name="required-entry" xsi:type="boolean">true</rule>
                    </validation>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">Title</label>
                <resizeEnabled>true</resizeEnabled>
                <resizeDefaultWidth>150</resizeDefaultWidth>
            </settings>
        </column>
        <column name="url_key">
            <settings>
                <filter>text</filter>
                <editor>
                    <validation>
                        <rule name="validate-identifier" xsi:type="boolean">true</rule>
                    </validation>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">URL Key</label>
                <resizeEnabled>true</resizeEnabled>
                <resizeDefaultWidth>150</resizeDefaultWidth>
            </settings>
        </column>
        <column name="creation_time" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <settings>
                <filter>dateRange</filter>
                <dataType>date</dataType>
                <label translate="true">Created</label>
                <resizeEnabled>true</resizeEnabled>
                <resizeDefaultWidth>150</resizeDefaultWidth>
            </settings>
        </column>
        <column name="update_time" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
            <settings>
                <filter>dateRange</filter>
                <dataType>date</dataType>
                <label translate="true">Modified</label>
                <resizeEnabled>true</resizeEnabled>
                <resizeDefaultWidth>150</resizeDefaultWidth>
            </settings>
        </column>
        <column name="meta_title">
            <settings>
                <filter>text</filter>
                <editor>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">Meta Title</label>
                <resizeEnabled>true</resizeEnabled>
                <resizeDefaultWidth>150</resizeDefaultWidth>
                <visible>false</visible>
            </settings>
        </column>
        <column name="meta_keywords">
            <settings>
                <filter>text</filter>
                <editor>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">Meta Keywords</label>
                <resizeEnabled>true</resizeEnabled>
                <resizeDefaultWidth>150</resizeDefaultWidth>
                <visible>false</visible>
            </settings>
        </column>
        <column name="meta_description">
            <settings>
                <filter>text</filter>
                <editor>
                    <editorType>text</editorType>
                </editor>
                <label translate="true">Meta Description</label>
                <visible>false</visible>
            </settings>
        </column>
    </columns>

2 Answers 2

0

add this on __construct in grid/collection.php

$this->addOrder('created_at', 'DESC');

0

**To sort an exported CSV file in descending order by the creation time, you'll need to perform the following steps:

1.Open the CSV file in a spreadsheet application like Microsoft Excel or Google Sheets.

2.Locate the column that represents the creation time in the CSV file. In the provided code snippet, it seems that the creation time is not explicitly mentioned. 3.If the creation time is not available in the CSV file, you'll need to extract it from another source or modify the export process to include it in the CSV file.

4.Once you have the creation time column, select the entire data range, including the header row.

5.Find the sorting option in your spreadsheet application. In Excel, you can find it under the "Data" tab, and in Google Sheets, it is located under the "Data" menu.

6.In the sorting options, specify the column that represents the creation time as the sorting key. Choose the option to sort in descending order.

7.Apply the sorting operation, and the data in the CSV file will be sorted in descending order based on the creation time.

8.Finally, you can save the sorted data as a new CSV file or overwrite the existing file.**

https://experienceleague.adobe.com/docs/commerce-admin/systems/data-transfer/data-csv.html?lang=en

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.