Because I want to display my submit button ($deleteSelected) above the pager I am having to output it in the template string. However, when the data provider returns no results the button is still printed.
My question is how do I access a method of the data provider object within the widget construction above.
I only want to output the $deleteSelected var if that data provider returns some data.
Thank you, but $model->pagination->itemCount is not a property of the model. But you have put me on the right track. I need to work out how to access the methods and properties of the grid widget and its parents inside the widget construct. I know $this gets me the controller class but this is no good to me either.
My mistake. $model->search() will return the CActiveDataProvider instance. You should be able to assign the value to a local variable in the statement used for assigning to the dataprovider property. Since I’m not sure about how param evaluation order is defined in the language, just assign $model->search() to a local variable before the widget creation. Then use the local variable (e.g. $dp) instead of $model->search().
Additional edit:
$dp->itemCount it is. Not $dp->pagination->itemCount
OK. If I access the itemCount property of CAtiveDataProvider (before it is returned to the widget) and make it a property of the model then I can use it in the widget.
My model:
class User extends CActiveRecord
{
public $itemCount;
...
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('username',$this->username,true);
$criteria->compare('role',$this->role,true);
$criteria->compare('email',$this->email,true);
$dataProvider= new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
//Pass CActiveDataProvider::itemCount to this model
$this->itemCount=$dataProvider->itemCount;
return $dataProvider;
}