Specify default sort header for a sortable table (tablesort) in D8? I am trying the table sort example module and noticed that I am unable to specify the default sort col once the page load. Meaning, when the page load for the first time it's always sorting by the first column in the table. In this case the number column (see screenshot). I tried 'sort'=&gt; 'DESC' and 'sort'=&gt; 'ASC' on the second and third col but it did not pick any as a default sort col.
  Here is the code generating the tablesort:

&lt;?php

namespace Drupal\tablesort_example\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Controller routines for tablesort example routes.
 */
class TableSortExampleController extends ControllerBase {

  /**
   * The Database Connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container-&gt;get('database')
    );
  }

  /**
   * TableSortExampleController constructor.
   *
   * @param \Drupal\Core\Database\Connection $database
   *   The database connection.
   */
  public function __construct(Connection $database) {
    $this-&gt;database = $database;
  }

  /**
   * A simple controller method to explain what the tablesort example is about.
   */
  public function description() {
    // We are going to output the results in a table with a nice header.
    $header = [
      // The header gives the table the information it needs in order to make
      // the query calls for ordering. TableSort uses the field information
      // to know what database column to sort by.
      ['data' =&gt; t('Numbers'), 'field' =&gt; 't.numbers'],
      ['data' =&gt; t('Letters'), 'field' =&gt; 't.alpha'],
      ['data' =&gt; t('Mixture'), 'field' =&gt; 't.random'],
    ];

    // Using the TableSort Extender is what tells  the query object that we
    // are sorting.
    $query = $this-&gt;database-&gt;select('tablesort_example', 't')
      -&gt;extend('Drupal\Core\Database\Query\TableSortExtender');
    $query-&gt;fields('t');

    // Don't forget to tell the query object how to find the header information.
    $result = $query
      -&gt;orderByHeader($header)
      -&gt;execute();

    $rows = [];
    foreach ($result as $row) {
      // Normally we would add some nice formatting to our rows
      // but for our purpose we are simply going to add our row
      // to the array.
      $rows[] = ['data' =&gt; (array) $row];
    }

    // Build the table for the nice output.
    $build = [
      '#markup' =&gt; '&lt;p&gt;' . t('The layout here is a themed as a table
           that is sortable by clicking the header name.') . '&lt;/p&gt;',
    ];
    $build['tablesort_table'] = [
      '#theme' =&gt; 'table',
      '#header' =&gt; $header,
      '#rows' =&gt; $rows,
    ];

    return $build;
  }

}
I was trying  $header= [ .... ['data' =&gt; .... 'sort'=&gt; 'DESC' , and that was not working. After step debugging, I found out the sort value is case sensitive. In function tablesort_get_order we have 

  if (empty($default) &amp;&amp; isset($header['sort']) &amp;&amp; ($header['sort'] == 'asc' || $header['sort'] == 'desc')) {
    $default = $header;
  } 


So it must be lower case to work. So the follwoing code achieve the desired behavior:

$header = [
      // The header gives the table the information it needs in order to make
      // the query calls for ordering. TableSort uses the field information
      // to know what database column to sort by.
      ['data' =&gt; t('Numbers'), 'field' =&gt; 't.numbers'],
      ['data' =&gt; t('Letters'), 'field' =&gt; 't.alpha'],
      ['data' =&gt; t('Mixture'), 'field' =&gt; 't.random', 'sort' =&gt; 'desc'],
    ];


hope this helps others.