Add pager to custom module

I built a module displaying data in a table. As there are lots of records to display I would like to add a pager. I have been able to display the pager but it’s not looping through the pages. Here is my code:

// Get header table from Drupal database
            $query = Drupal::database()->select('header', 'n');
			   $query->addJoin('INNER', 'taxonomy_term_field_data', 'ttfd', 'n.CUSTNAME = ttfd.name');
            $query->fields('n', array('CUSTNAME', 'PSTATUS_ID', 'SAMPLE_ID', 'STATUS', 'DATE_SAMPLED', 'OWNER_REFERENCE', 'SERIALNO', 'LOCATION', 'DESCRIPTION'));
            $group = $query->orConditionGroup()
                 ->condition('PSTATUS_ID', 40.00)
                 ->condition('PSTATUS_ID', 50.00)
                 ->condition('PSTATUS_ID', 60.00)
                 ->condition('PSTATUS_ID', 80.00);
            $query->condition($group);
			      $query->condition('ttfd.name',$company,'in');
            // $query->range(0, 100);
            $query->orderBy('DATE_SAMPLED', 'DESC');
            $pager = $query->extend('DrupalCoreDatabaseQueryPagerSelectExtender')->limit(50); // Pager limited to 50
            $result = $pager->execute();
                // Create the row element.
                $rows = array();
                foreach ($result as $row => $content) {
                    $sample_id = $content->SAMPLE_ID;
                    $sample_id_url = Url::fromUri('internal:/oil-lab/sample?id='.$sample_id);
                    $sample_id_link = Drupal::l($sample_id, $sample_id_url);
                    $pdf_download_img = t('<img src="@pdf-icon" alt="Download PDF" width="25">', array('@pdf-icon' => '/themes/custom/powerlink/images/pdf-icon.png',));
                    $pdf_download_url = Url::fromUri('internal:/pdfgen.php?id='.$sample_id, array('attributes' => array('target' => '_blank')));
                    $pdf_download_link = Drupal::l($pdf_download_img, $pdf_download_url);$csv_download_img = t('<img src="@csv-icon" alt="Download CSV" width="25">', array('@csv-icon' => '/themes/custom/powerlink/images/csv-icon.png',));
                    $csv_download_url = Url::fromUri('internal:/csvgen.php?id='.$sample_id, array('attributes' => array('target' => '_blank')));
                    $csv_download_link = Drupal::l($csv_download_img, $csv_download_url);
                    $rows[] = array('data' => array($content->CUSTNAME, $sample_id_link, $content->STATUS, $content->DATE_SAMPLED, $content->OWNER_REFERENCE, $content->SERIALNO, $content->LOCATION, $content->DESCRIPTION, $pdf_download_link, $csv_download_link));
                }
                // Create the header.
                $header = array('Customer', 'Sample', 'Status', 'Sample Date', 'Owner Ref', 'Serial No', 'Location', 'Description', 'Download');
                $output = [];
                $output[] = array(
                  '#theme' => 'table',    // Here you can write #type also instead of #theme.
                    '#attributes' => array(
                      'id' => array(
                        'completed-tasks',
                      ),
                      'class' => array(
                        'filterable',
                      ),
                    ),
                  '#header' => $header,
                  '#rows' => $rows,
                  '#attached' => array(
                    'library' => array(
                      'oil_lab/table_filter_scripts',
                    ),
                  )
                );
                $output[] = ['#type' => 'pager']; // Here is the pager
            return $output;

Any help in getting that pager to work would be greatly appreciated.

Thank you

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed