filtering gridview with mailto function

Hello,

I got the next situation:

In the detail view of an event, I also display a list of subscribers (with name,email, attending columns) to that event, displayed in a gridview (which itself uses paging per 10 items).

Problem:

I want to be able to have filtering on top of that gridview, and also a way to e-mail that filtered result.

Even if the filtered result is more than 10 items, the button or link should call a mailto for all the filtered persons.

How can this be done? I know it must be possible, but I’m just in my first yii project and not experienced enough at the moment.

I think you could see what can be done to return the sum of the filtered results here.

I’m sepaking of this part

In your case, you would manually concatenate the email field instead of summing, like (not tested)


public static function recipients($provider)

{

    $recipients = '';

    foreach($provider->data as $item)

        $recipients .= ($recipients != '' ? ', ' : '') . $item->email;

    return $recipients;

}

Tell us if it works please

Unless I miss something, I don’t think that’s exactly what I need.

What I need, is first of all possibility to have filtering working on a view page, in a list of related items.

Added to that, there must be another list below that (the list of mail-recipients) which synchronizes according to the filter applied in the on above.

Something like this:

But when clicking the mail-button, I want all of the subscribers, also the ones from page 2-5.

A paginated gridview doesn’t know the whole items, because the data provider has limited the returned results.

So I think that using a separated controller for the mailing function will make things simpler.

The filtering parameters are sent to the current controller in $_GET[‘Subscriber’] (the name is my guess). So why don’t you save it in the session and use it in the mailing controller?

A rough sketch might be …




public function actionSomething()

{

	...

	$model = new Subscriber('search');

	$model->unsetAttributes();  // clear any default values

	if (isset($_GET['Subscriber']))

	{

		$model->attributes = $_GET['Subscriber'];

		Yii::app()->user->setState('SubscriberSearchParams', $_GET['Subscriber']);

	}

	...

}


public function actionMailToSubscribers()

{

	$model = new Subscriber('search');

	$model->unsetAttributes();  // clear any default values

	$model->attributes = Yii::app()->user->getState('SubscriberSearchParams');

	$dataProvider = $model->search_all();   // you will need a non-paginated version of search()

	foreach($dataProvider->data as $subscriber)

	{

		...

	}

	...

}