@MikMik

Как динамически добавить GridView на страницу?

Суть примерно такая - надо по нажатию на кнопку добавлять пустую таблицу на страницу, при этом делать это неограниченное количество раз, то есть нажал 3 раза появилось 3 таблицы.
Подскажите в какую сторону копать?
  • Вопрос задан
  • 33 просмотра
Пригласить эксперта
Ответы на вопрос 1
@MikMik Автор вопроса
Делаю так...

Контролер:
public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $sectionsList = EstimateSection::listOfSection($model->id);

        foreach ($sectionsList as $section) {
            $resources = new ActiveDataProvider([
                'query' => EstimateResource::find()->where(['estimate_section_id' => $section->id])
            ]);

            $sections[] = [
                'section' => $section,
                'resources' => $resources,
            ];
        }


        if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
            return $this->render('update', [
                'model' => $model,
                'sections' => $sections
            ]);
        }

        return $this->render('update', [
            'model' => $model,
            'sections' => $sections
        ]);
    }

public function actionAjaxCreateSection($estimate_id) {
        
        $section = new EstimateSection();
        $section->estimate_id = $estimate_id;
        $section->save();

        $resources = new ActiveDataProvider([
            'query' => EstimateResource::find()->where(['estimate_section_id' => $section->id])
        ]);

        return $this->renderAjax('_new_section', [
            'resources' => $resources,
            'section_id' => $section->id,
        ]);
    }
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы