/**
* An example controller.
*/
class GenerateCertificateTable extends ControllerBase {
/**
* Returns a render-able array for a test page.
*/
public function content($nid) {
$query = \Drupal::database()->select('users_field_data', 'u');
$query->fields('u', ['uid','name','mail']);
//For the pagination we need to extend the pagerselectextender and
//limit in the query
$pager = $query->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(10);
$results = $pager->execute()->fetchAll();
// dump($results);
// Initialize an empty array
$header = [
'uid' => t('UID'),
'mail' => t('mail'),
'name' => t('Username'),
];
$output = array();
// Next, loop through the $results array
foreach ($results as $result) {
if ($result->uid != 0 && $result->uid != 1) {
$options[$result->uid] = [
'uid' => $result->uid,
'mail' => $result->mail,
'name' => $result->name,
];
}
}
$form['table'] = [
'#type' => 'table',
'#header' => $header,
'#options' => $output,
'#js_select' => TRUE,
'#multiple' => TRUE,
'#required' => TRUE,
];
// Finally add the pager.
$form['pager'] = array(
'#type' => 'pager'
);
$build[] = $form;
return $build;
}
}
I am trying to create table form using tableselect element but even after I get the data it shows empty data value.