View source  
  <?php
namespace Drupal\views_summarize\Plugin\views\style;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\style\Table;
class TableSummarized extends Table {
  
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    
    $form['#theme'] = 'views_summarize_style_plugin_summarized_table';
    $options = $this
      ->getHandlers();
    $columns = $this
      ->sanitizeColumns($this->options['columns']);
    foreach (array_keys($columns) as $field) {
      $safe = str_replace([
        '][',
        '_',
        ' ',
      ], '-', $field);
      $id = 'edit-style-options-columns-' . $safe;
      $form['info'][$field]['summarize'] = [
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => !empty($this->options['info'][$field]['summarize']) ? $this->options['info'][$field]['summarize'] : 'none',
        '#dependency' => [
          $id => [
            $field,
          ],
        ],
      ];
    }
    $form['summary_only'] = [
      '#title' => t('Display the summary row only'),
      '#description' => t('If checked only the summary row will be displayed,'),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['summary_only']),
    ];
  }
  
  protected function getHandlers() {
    return [
      'none' => t('None'),
      'count' => t('Count'),
      'total' => t('Total'),
      'currency' => t('Total (Currency)'),
      'average' => t('Average (include empty values)'),
      'average_no_empties' => t('Average (exclude empty values)'),
      'range' => t('Range'),
      'spread' => t('Spread'),
    ];
  }
}