Also, if anyone is using POSTed data to determine the contents of the grid view, i.e. a date range, here is a way to make sure that data is persisted on each sort request:
Ensure the action in your controller can accept both POST and GET request data by using the $_REQUEST variable
Use the $sort->params attribute to set the request data into the CSort object (This data will be appended to the request URL when sorting
public function actionIndex()
{
$model = new PixelReport;
$reportDataProvider = false;
// If dates have been posted
// get the commission data
if (isset($_REQUEST['PixelReport'])) {
// Validate the date range
$model->attributes = $_REQUEST['PixelReport'];
if ($model->validate()) {
// Get your data from the model
$data = $model->getReportData();
// Create a new CSort object
$sort = new CSort();
// One attribute for each column of data
$sort->attributes = array(
'campaign_title',
'unique_clicks',
'leads',
'total',
);
// Set the default order
$sort->defaultOrder = array(
'total'=>CSort::SORT_DESC,
);
// Persist the request by adding the dates to the sort params
$sort->params = array(
'PixelReport' => $_REQUEST['PixelReport'],
);
// Create data provider for the Grid View
$reportDataProvider = new CArrayDataProvider($data, array(
'id'=>'campaign-summary',
'keyField'=>'campaign_id',
'sort'=>$sort,
'pagination'=>array(
'pageSize'=>20,
),
));
}
}
$this->render('index', compact('model', 'reportDataProvider'));
}