Create custom table with pagination I have a function in a controller which shows data in table format. I need pagination and styling for the table. I tried as follow.

MyController.php

public function my_requests() {       
        //load the current user details
        $user= User::load(\Drupal::currentUser()-&gt;id());
        $user_id = \Drupal::currentUser()-&gt;id();

        //Query the database
        $query = \Drupal::entityQuery('node')
           -&gt;tableSort($header)
           -&gt;condition('status', 1)
           -&gt;condition('type', "forward_proxy_request")
           -&gt;condition('uid', $user_id)
           -&gt;sort('nid' , 'ASC');
        $table_sort = $query-&gt;extend('Drupal\Core\Database\Query\TableSortExtender')-&gt;orderByHeader($header);
        $pager = $table_sort-&gt;extend('Drupal\Core\Database\Query\PagerSelectExtender')-&gt;limit(10);
        $nids = $pager-&gt;execute();

        //creates the table header
        $header = [
                'Node id',
                'title',               
                'Name',
                'Ip',
                'SLU',
            ];  
        foreach ($nids as $nid) {
            $node = Node::load($nid);
            $row  = [
                'data' =&gt; [
                    $node-&gt;nid-&gt;value,
                    $node-&gt;title-&gt;value, 
                    $node-&gt;field_p_name[0]-&gt;value,
                    $node-&gt;field_ip[0]-&gt;value,
                    $node-&gt;field_p_slu[0]-&gt;value,
                ],
            ];
            $rows[] = $row;
        }
        //Build the table
        $build = [
          'table'           =&gt; [
          '#prefix'        =&gt; '&lt;h1&gt;My Requests&lt;/h1&gt;',
          '#theme'         =&gt; 'table',
          '#attributes'    =&gt; [
              'data-striping' =&gt; 0
          ],
          '#header' =&gt; $header,
          '#rows'   =&gt; $rows,
      ],
    ];
    //for pagination
    $build['pager'] = array(
        '#type' =&gt; 'pager'
    );

     return $build;          
}


But it throws an error.


  Error: Call to undefined method Drupal\\Core\\Entity\\Query\\Sql\\Query::extend() in
  /var/www-drupal/modules/ga/src/Controller/MyController.php on line
  196 


Without extendQuery, it shows a plain table without any style.


  


How do I resolve this issue?
Here is an example of sortable table with pagination.

$header = [
  'id' =&gt; [
    'data' =&gt; $this-&gt;t('ID'),
    'specifier' =&gt; 'nid',
  ],
  'title' =&gt; [
    'data' =&gt; $this-&gt;t('Title'),
    'specifier' =&gt; 'title',
  ],
  'created' =&gt; [
    'data' =&gt; $this-&gt;t('Created'),
    'specifier' =&gt; 'created',
    // Set default sort criteria.
    'sort' =&gt; 'desc',
  ],
  'uid' =&gt; [
    'data' =&gt; $this-&gt;t('Author'),
    'specifier' =&gt; 'uid',
  ],
];

$storage = \Drupal::entityTypeManager()-&gt;getStorage('node');

$query = $storage-&gt;getQuery();
$query-&gt;condition('status', \Drupal\node\NodeInterface::PUBLISHED);
$query-&gt;condition('type', 'article');
$query-&gt;tableSort($header);
// Default value is 10.
$query-&gt;pager(15);
$nids = $query-&gt;execute();

$date_formatter = \Drupal::service('date.formatter');
$rows = [];
foreach ($storage-&gt;loadMultiple($nids) as $node) {
  $row = [];
  $row[] = $node-&gt;id();
  $row[] = $node-&gt;toLink();
  $created = $node-&gt;get('created')-&gt;value;
  $row[] = [
    'data' =&gt; [
      '#theme' =&gt; 'time',
      '#text' =&gt; $date_formatter-&gt;format($created),
      '#attributes' =&gt; [
        'datetime' =&gt; $date_formatter-&gt;format($created, 'custom', \DateTime::RFC3339),
      ],
    ],
  ];
  $row[] = [
    'data' =&gt; $node-&gt;get('uid')-&gt;view(),
  ];
  $rows[] = $row;
}

$build['table'] = [
  '#type' =&gt; 'table',
  '#header' =&gt; $header,
  '#rows' =&gt; $rows,
  '#empty' =&gt; $this-&gt;t('No content has been found.'),
];

$build['pager'] = [
  '#type' =&gt; 'pager',
];