Tablesort with EntityQuery Inside a block plugin I'm creating a table (in Drupal8). Like so

            $header = [
                t('Name'),
                t('Number'),
                t('Rank'),
            ];
            $nids = \Drupal::entityQuery('node')
                -&gt;extend('Drupal\Core\Database\Query\TableSortExtender')
                -&gt;orderByHeader($header)
                -&gt;condition('type', 'my_content_type')
                -&gt;condition('status', 1)
                -&gt;pager(5)
                -&gt;execute();
            foreach ($nids as $nid) {
                $node            = \Drupal\node\Entity\NODE::load($nid);
                $row = [
                    'data' =&gt; [
                        $node-&gt;title-&gt;value,
                        $node-&gt;field_number-&gt;value,
                        $node-&gt;field_rank-&gt;value,
                    ],
                ];
                $rows[] = $row;
              }
            $render = [
                'table'           =&gt; [
                    '#prefix'        =&gt; '&lt;h1&gt;Entries&lt;/h1&gt;',
                    '#theme'         =&gt; 'table',
                    '#attributes'    =&gt; [
                        'data-striping' =&gt; 0
                    ],
                    '#header' =&gt; $header,
                    '#rows'   =&gt; $rows,
                ],
            ];
            return $render;


Without the code below

 -&gt;extend('Drupal\Core\Database\Query\TableSortExtender')
 -&gt;orderByHeader($header)


the table renders just fine, but if I do include it I get the error


  Call to undefined method Drupal\Core\Entity\Query\Sql\Query::extend()


I'm guessing that it ->extend does not work on EntityQueries, but if that's the case how can I add table sorting to my table?

UPDATE: I've changed my $header array to include 'field' like so

            $header = [
                [
                    'data'  =&gt; t('Title'),
                    'field' =&gt; 'title'
                ],
                [
                    'data'  =&gt; t('Race'),
                    'field' =&gt; 'field_number'
                ],
                [
                    'data'  =&gt; t('Time'),
                    'field' =&gt; 'field_rank',
                ],
            ];


and tried adding 

 -&gt;tableSort($header)


to the query and removing extend and orderByHeader from the query but then I receive the following error


  Drupal\Core\Entity\Query\QueryException: '' not found in
  Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable()


UPDATE 2:
I tried changing the $header array to use a specifier and type property like so.

                    'data'      =&gt; t('Name'),
                    'type'      =&gt; 'field',
                    'specifier' =&gt; [
                        'field'    =&gt; 'title',
                        'column'   =&gt; 'value',
                    ],


But I end up with the same error and get an additional error


  Undefined index: specifier in
  Drupal\Core\Entity\Query\QueryBase->tableSort()
Following some of the information found in Berdirs answer and comments I was able to arrive at a solution.

I formatted my header like so:

            $header = [
                'title'      =&gt; [
                    'data'      =&gt; t('title'),
                    'field'     =&gt; 'title',
                    'specifier' =&gt; 'title',
                ],
                'number'       =&gt; [
                    'data'      =&gt; t('Number'),
                    'field'     =&gt; 'field_number',
                    'specifier' =&gt; 'field_number',
                ],
                'time'       =&gt; [
                    'data'      =&gt; t('Time'),
                    'field'     =&gt; 'field_rank',
                    'specifier' =&gt; 'field_rank',
                ],
            ],


I then performed the EntityQuery like so

            $nids = \Drupal::entityQuery('node')
                -&gt;tableSort($header)
                -&gt;condition('type', 'my_content_type')
                -&gt;condition('status', 1)
                -&gt;pager($items_per_page)
                -&gt;execute();


I formatted my rows like so

                $row = [
                    'data' =&gt; [
                        $node-&gt;title-&gt;value,
                        $node-&gt;field_number-&gt;value,
                        $node-&gt;field_rank-&gt;value,
                ];


After that generating the table was easy

            $render = [
                'table'           =&gt; [
                    '#prefix'        =&gt; '&lt;h1&gt;Entries&lt;/h1&gt;',
                    '#theme'         =&gt; 'table',
                    '#attributes'    =&gt; [
                        'data-striping' =&gt; 0
                    ],
                    '#header' =&gt; $header,
                    '#rows'   =&gt; $rows,
                ],
            ];


The important parts I was missing is the proper format for $header. And using ->tableSort($header) instead of                 ->extend('Drupal\Core\Database\Query\TableSortExtender')
                ->orderByHeader($header) in my entityQuery