how to use an entity query to make a sortable table
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.