how to use an entity query to make a sortable table I need to use an entity query such as this: 

$query = \Drupal::entityQuery('node')
-&gt;condition('type', 'blog_post')
-&gt;sort('field');


$nids = $query->execute();

to make a table that is sortable in a custom module .  I found instructions on how to do this with a normal query , (below) how can I make this work for this entity query 

  $header = array(
  // We make it sortable by name.
  array('data' =&gt; $this-&gt;t('Name'), 'field' =&gt; 'name', 'sort' =&gt; 'asc'),
  array('data' =&gt; $this-&gt;t('Content')),
);

$db = \Drupal::database();
$query = $db-&gt;select('config','c');
$query-&gt;fields('c', array('name'));
// The actual action of sorting the rows is here.
$table_sort = $query-&gt;extend('Drupal\Core\Database\Query\TableSortExtender')
                    -&gt;orderByHeader($header);
// Limit the rows to 20 for each page.
$pager = $table_sort-&gt;extend('Drupal\Core\Database\Query\PagerSelectExtender')
                    -&gt;limit(20);
$result = $pager-&gt;execute();

// Populate the rows.
$rows = array();
foreach($result as $row) {
  $rows[] = array('data' =&gt; array(
    'name' =&gt; $row-&gt;name,
    'content' =&gt; '[BLOB]', // This hardcoded [BLOB] is just for display purpose only.
  ));
}

// The table description.
$build = array(
  '#markup' =&gt; t('List of All Configurations')
);

// Generate the table.
$build['config_table'] = array(
  '#theme' =&gt; 'table',
  '#header' =&gt; $header,
  '#rows' =&gt; $rows,
);

// Finally add the pager.
$build['pager'] = array(
  '#type' =&gt; 'pager'
);

return $build;


}
}
EntityQuery doesn't appear to have the extend() function that this example relies on, so much of what's happening in the example will need to be done manually.

You can get the sort parameters from the request object

$sort_field = \Drupal::request()-&gt;query-&gt;get('order');
$sort_order = \Drupal::request()-&gt;query-&gt;get('sort');


With those, you can update your query to something like.

$query = \Drupal::entityQuery('node')
  -&gt;condition('type', 'blog_post')
  -&gt;sort($sort_field, $sort_direction);
$nids = $query-&gt;execute();
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);


Then use $nodes to build your $rows array as in the example.