public function run() { SelectAsset::register($this->view); FilterAsset::register($this->view); $values = []; foreach ($this->data as $value) { $value = strval($value); $values[$value] = $value; } if (!$this->default) { $this->default = $this->multiple ? array_keys($values) : key($values); } $selected = $this->selected($this->default); // Setup options $options = ['id' => $this->name, 'name' => $this->name . '[]', 'style' => 'width: 300px;', 'class' => 'selectpicker']; $extra = ['title' => 'Not selected']; if ($this->multiple) { $extra['multiple'] = 'multiple'; } if ($this->placeholder) { $extra['title'] = strval($this->placeholder); } $options = array_merge($options, $extra); if (!$this->method) { $this->method = 'get'; } // Render echo Html::beginForm(Url::canonical(), $this->method, ['data-pjax' => '1', 'id' => $this->name]); echo Html::beginTag('select', $options, ['data-pjax' => '1']); echo Html::renderSelectOptions($selected, $values); echo Html::endTag("select"); echo Html::endForm(); parent::run(); }
public function run() { if (!$this->header) { $this->header = $this->data->header(); } echo Html::beginTag('table', ['id' => $this->name, 'class' => 'table table-bordered']); // Header echo Html::beginTag('tr'); foreach ($this->header as $head) { echo Html::tag('th', strval($head)); } echo Html::endTag('tr'); // Data foreach ($this->data as $item) { echo Html::beginTag('tr'); foreach (Widget::toArray($item) as $value) { echo Html::tag('td', strval($value)); } echo Html::endTag('tr'); } echo Html::endTag('table'); parent::run(); }
public function init() { parent::init(); }