Guest User

Untitled

a guest
Jun 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. //submit button
  2. $form['action'] = [
  3. '#prefix' => '<div id = "ajax_submit">',
  4. '#name' => 'ajax_action',
  5. '#type' => 'button',
  6. '#value' => $this->t('Submit'),
  7. '#ajax' => [
  8. 'callback' => '::setMessage',
  9. 'wrapper' => 'scrollable',
  10. 'method' => 'replace',
  11. 'effect' => 'fade',
  12. ],
  13. '#suffix' => '</div></div></div>',
  14. ];
  15.  
  16.  
  17. //table element
  18. $form['table'] = array(
  19. '#prefix' => '<div id="scrollable" class = "col-md-8"><h4>View Data</h4>',
  20. '#type' => 'tableselect',
  21. '#header' => $header,
  22. '#options' => $options,
  23. '#disabled' => $disabled,
  24. '#attributes' => array('id' => 'sort-table'),
  25. '#empty' => t('Select criteria and search data'),
  26. );
  27.  
  28. //pager element
  29. $form['pager'] = array(
  30. '#type' => 'pager',
  31. '#suffix' => '</div>',
  32. );
  33.  
  34. //function to obtain #options
  35. if ($form_state->getTriggeringElement()['#name'] == 'ajax_action') {
  36. $options = array();
  37. $header = [
  38. 'subject_id' => t('Subject ID'),
  39. 'ct_availability' => t('CT Availability'),
  40. 'sex' => t('Sex'),
  41. 'race' => t('Race'),
  42. 'cardiovascular_disease' => t('Cardiovascular Disease'),
  43. 'registration_age' => t('Registration_Age'),
  44. ];
  45. $options = $this->getOptions($form_state); //function to get #options
  46. $form['table']['#header'] = $header;
  47. $form['table']['#options'] = $options;
  48. }
  49.  
  50. public function setMessage(array $form, FormStateInterface $form_state) {
  51. return (array($form['table'], $form['pager']));
Add Comment
Please, Sign In to add comment