We're Moving to a New Support Platform – Starting June 1st!

We’re excited to let you know that starting June 1st, we’ll be transitioning to a new support system that will be available directly on our product websites – Amelia, wpDataTables, and Report Builder. In fact, the new support platform is already live for Amelia and wpDataTables, and we encourage you to reach out to us there.

You'll always be able to reach us through a widget in the bottom right corner of each website, where you can ask questions, report issues, or simply get assistance.

While we still do not offer live support, a new advanced, AI-powered assistant, trained on our documentation, use cases, and real conversations with our team, is there to help with basic to intermediate questions in no time.

We're doing our best to make this transition smooth and hassle-free. After June 1st, this current support website will redirect you to the new "Contact Us" pages on our product sites.

Thanks for your continued support and trust – we’re excited to bring you an even better support experience!

Okay
  Public Ticket #3730123
When clicking it sort, is it possible for it to default to descending rather than ascending?
Closed

Comments

  • Khanh Vo started the conversation

    Hi there,

    When clicking a column sorting, is it possible for it to default to descending rather than ascending?

    Thanks,

    Khanh

  •  1,895
    Miloš replied

    Hello,
    It is not possible with a built-in option, but our developers have a custom workaround code edit which you can use, in order to change how the default 'initial sort order' is triggered when clicking in the Headers.

     

    Please find this JS file in our Plugin's files - via your FTP ( or Hosting File Manager) in this path :

    ..\wp-content\plugins\wpdatatables\assets\js\wpdatatables\wpdatatables.js.

    Find this piece of code, it should be around line 2255 ( best is to use CTRL+F to search for it rather than looking at exact lines, since our devs change code during some Updates):

    $('table.wpDataTable:not(.wpdtSimpleTable)').each(function () {
                var tableDescription = JSON.parse($('#' + $(this).data('described-by')).val());
                wdtRenderDataTable($(this), tableDescription);
            });
    1387835047.png

    Add this under it :

    $('th.sort').on('click', function(){
        var tableDescription = JSON.parse($('#' + $('table.wpDataTable:not(.wpdtSimpleTable)').data('described-by')).val());
        var oSettings = wpDataTables[tableDescription.tableId].fnSettings();
        oSettings.aaSorting[0][1] = oSettings.aaSorting[0][1] === 'asc' ? 'desc' : 'asc';
        oSettings.aoColumns[$(this)[0].cellIndex].asSorting[1];
        wpDataTables[tableDescription.tableId].fnDraw();
    });

    ( That is the full edited code which works on Manual Tables, too)

    So in the end, that entire piece of code should look like this :

    $('table.wpDataTable:not(.wpdtSimpleTable)').each(function () {
                var tableDescription = JSON.parse($('#' + $(this).data('described-by')).val());
                wdtRenderDataTable($(this), tableDescription);
            });
            $('th.sort').on('click', function(){
                var tableDescription = JSON.parse($('#' + $('table.wpDataTable:not(.wpdtSimpleTable)').data('described-by')).val());
                var oSettings = wpDataTables[tableDescription.tableId].fnSettings();
                oSettings.aaSorting[0][1] = oSettings.aaSorting[0][1] === 'asc' ? 'desc' : 'asc';
                oSettings.aoColumns[$(this)[0].cellIndex].asSorting[1];
                wpDataTables[tableDescription.tableId].fnDraw();
            });
        });
    3785461727.png

    Save changes, and now this is going to make all Headers in all your Tables have a default sorting order of Descending - when any Header is clicked on.

    Then the User needs to click again to switch it as  "Ascending" order.


    Let us know if that works, now all your tables ( server side and non server side) should be sorting as 'descending' by default when the Header is clicked on the first time.

     

    If you need us to edit this code for you, please provide me a temporary WP-admin (administrator) user for your site where this happens, and FTP credentials.

    We do not interfere with any data or anything else except for the plugin (in case that’s a production version of the site), and of course, we do not provide login data to third parties. 

    You can write credentials here just check PRIVATE Reply so nobody can see them except us.

     

    Thank you.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  • Khanh Vo replied

    Thank you Miloš.

  •   Miloš replied privately