I have view with 3 widgets.
Two TbButton
widgets and one TbExtendedGridView
widget.
Buttons are used for "insert new user" and "create pdf". TbExtendedGridView is used to list current users and their attributes.
TbExtendedGridView
has filtering turned on and is working fine.
Controller is simple. It detects if there is an AjaxRequest. If there is, it filters data according to GET variables. If not, it renders a default view that shows all users.
What i need is the ability to create a PDF of that table.
I installed PDF extensions and created PDFReport controller. When user clicks on "create pdf" button, he goes to that controller which than creates PDF. All is fine until I want to create PDF out of filtered data.
First thing that came across my mind was to pass variables from filters to "Create pdf" button's link so that once it's clicked i will send relevant data to PDFReport controller which would than be able to filter data and create filtered PDF.
Problem is that filtering is done via AJAX request and it refreshes only table. Button widgets are not refreshed and i don't know how to send new link to "create PDF" button.
I have no idea how to make this work.
Controller action:
public function actionIndex()
{
// if submited by filters, get only filtered data
if( Yii::app()->request->isAjaxRequest && isset($_GET['users']))
{
$criteria=new CDbCriteria;
foreach ($_GET['users'] as $key => $value) {
if ($value != "") {
if (preg_match('/^(["\']).*\1$/m', $value)) {
$criteria->addInCondition($key,array($value),$operator='AND');
}
else
{
$criteria->addsearchCondition($key,$value,$like='LIKE');
}
}
}
$data=new CActiveDataProvider(
'users',
array(
'criteria'=>$criteria,
'pagination' => array('pageSize' => 30)
)
);
$createPDFurl = "test2";
$this->render('index',array('model'=>$data, 'createPDFurl' => $createPDFurl));
}
//else full table
else
{
$data=new CActiveDataProvider(
'users',
array('pagination' => array('pageSize' => 30))
);
$createPDFurl = "test1";
$this->render('index',array('model'=>$data, 'createPDFurl' => $createPDFurl));
}
}
and view:
<?php
$this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Unos novog zaposlenika',
'type' => 'primary',
'url' => $createPDFurl,
)
);
$this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Kreiraj PDF',
'type' => 'primary',
'url' => $createPDFurl,
)
);
$godisnji_width = "100px";
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'fixedHeader' => true,
'headerOffset' => 40, // 40px is the height of the main navigation at bootstrap
'type' => 'striped bordered condensed',
'dataProvider' => $model,
'filter' => $model->model,
'responsiveTable' => true,
'template' => "{pager}{items}{summary}{pager}\n{extendedSummary}",
'ajaxUrl'=> $this->createUrl('/site/index'),
'pager' => array(
'nextPageLabel' => 'Sljedeća',
'prevPageLabel' => 'Prijašnja',
'firstPageLabel' => 'Prva',
'lastPageLabel' => 'Posljednja'
),
'summaryText' => 'Prikazano {start}-{end} od {count} unosa.',
'columns' => array(
'prezime',
'ime',
'radno_mjesto',
'odjel',
'broj_dana',
array('name'=>'godisnji', 'htmlOptions'=>array('width' => $godisnji_width), 'headerHtmlOptions'=>array('width' => $godisnji_width), 'filterHtmlOptions'=>array('width' => $godisnji_width)),
'stari_godisnji',
'bolovanje',
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
echo $createPDFurl;
When you load index page 1st, you get 2 nice buttons and 1 nice table full of data and echo of that test variable: "test1".
When i enter something into filter, my table changes but test variable stays "test1". I'm pretty much sure i know why, because Ajax changes only table, which is good thing as that's reason Ajax is there, but how to force it refresh other widgets or how to push that new data to rest of the page i have no idea.