Okay
  Public Ticket #2926440
Auto Descending Sort Order
Closed

Comments

  • Ed Kraft started the conversation

    Hey Guys,

    I have a table similar to the Premier league table, with point totals across multiple columns.  When I click the header to sort each rounds, the default sort order is ascending (showing the lowest point totals first).  Can I make the default sort order descending for these columns?  Within the editor, the only way I see how to do this is making each column sortable on load, where the option for ascending or descending exists.  However I only want to sort by total points on load of the table, not every column.

    Within regular data tables, the code would look something like this:

    { "orderSequence": [ "desc", "asc"], "targets": [ 4, 6, 8, 10, 12 ] }, // set column sort order for points to descending when clicked

    That code sets the default sort order to 'descending' for those columns.  Can I do that with custom JS here as well?

    Thanks.

  •  472
    Isidora replied

    Hi Ed,

    Thank you for your purchase.

    Sorry for the late response, we have some agents that have contracted Covid-19, so our team is cut in half.

    Your request require custom solution.

    1) You can use hook wpdatatables_filter_table_description(available filters)

    wpdatatables_filter_table_description( $object, $tableId, wpDataTableObject )

    This filter is applied to an object (PHP’s StdObj), which is later printed as a table’s data attribute (json_encoded), and used to initialize the DataTables instance, and to describe other table settings and parameters that are used by the frontend JS library.

    $object is the PHP StdObj which contains all the necessary fields for initializing the table

    $tableId is the table identifier from the MySQL table (wp_wpdatatables)

    $wpDataTableObject is the WPDataTable object

    2) You can use Datatable API over wpDataTables object. All wpDataTables existing on the page are reflected in the global JavaScript object called ‘wpDataTables‘. If you check this variable in the JS developer console you will see the wpDataTables as properties of this object. More info.


    Please note that using wpDataTable hooks and callbacks requires certain level of programming skills and included support refers only to advice.

    Best regards.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

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

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables