I need to export records from a cgridview to a pdf in the same order that the user chooses, and respecting the applyed filtering. It all works fine at the filter part but I can’t get the export to respect the order from the cgridview. Can someone pls help?
Here’s my relevant code:
controler:
public function actionIndex()
{
$model=new activitylog('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['activitylog']))
$model->attributes=$_GET['activitylog'];
Yii::app()->user->setState('logModel',$model);
$this->render('admin',array(
'model'=>$model,
));
}
public function actionPrint()
{
if(Yii::app()->user->getState('logModel')):
$model=Yii::app()->user->getState('logModel');
else:
$model=new activitylog('search');
$model->unsetAttributes();
endif;
$dataProvider = $model->search();
$dataProvider->pagination=false; // for retrieve all models
$larguras=array('10','35','20','20','30','50');
Yii:utils::makeTablePdf($dataProvider,
' ', //titulo
'ficheiro',
'Atividade no Sistema', //subtitulo
$larguras
);
}
Everything is ok with filtering. PDF only prints filtered records. But the sort order from the grid (the one resulting from clicking column headers) is not respected. My model search function goes as follows:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('inserted_date',$this->inserted_date,true);
$criteria->compare('username',$this->username,true);
$criteria->compare('func',$this->func,true);
$criteria->compare('ip_user',$this->ip_user,true);
$criteria->compare('description',$this->description,true);
return new CActiveDataProvider($this, array(
'sort'=>array('defaultOrder'=>'inserted_date DESC'),
'pagination'=>array('pageSize'=>50),
'criteria'=>$criteria,
));
Any ideas to help the newbie?