Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //submit button
- $form['action'] = [
- '#prefix' => '<div id = "ajax_submit">',
- '#name' => 'ajax_action',
- '#type' => 'button',
- '#value' => $this->t('Submit'),
- '#ajax' => [
- 'callback' => '::setMessage',
- 'wrapper' => 'scrollable',
- 'method' => 'replace',
- 'effect' => 'fade',
- ],
- '#suffix' => '</div></div></div>',
- ];
- //table element
- $form['table'] = array(
- '#prefix' => '<div id="scrollable" class = "col-md-8"><h4>View Data</h4>',
- '#type' => 'tableselect',
- '#header' => $header,
- '#options' => $options,
- '#disabled' => $disabled,
- '#attributes' => array('id' => 'sort-table'),
- '#empty' => t('Select criteria and search data'),
- );
- //pager element
- $form['pager'] = array(
- '#type' => 'pager',
- '#suffix' => '</div>',
- );
- //function to obtain #options
- if ($form_state->getTriggeringElement()['#name'] == 'ajax_action') {
- $options = array();
- $header = [
- 'subject_id' => t('Subject ID'),
- 'ct_availability' => t('CT Availability'),
- 'sex' => t('Sex'),
- 'race' => t('Race'),
- 'cardiovascular_disease' => t('Cardiovascular Disease'),
- 'registration_age' => t('Registration_Age'),
- ];
- $options = $this->getOptions($form_state); //function to get #options
- $form['table']['#header'] = $header;
- $form['table']['#options'] = $options;
- }
- public function setMessage(array $form, FormStateInterface $form_state) {
- return (array($form['table'], $form['pager']));
Add Comment
Please, Sign In to add comment