Reputation: 4283
If only single result found from the default Yii ajax search, I want to redirect to it's view action. How can I trigger the redirection?. (This is similar to Google's "I'm feeling lucky" Option)
Upvotes: 0
Views: 597
Reputation: 4283
Answering myself,
I endup with javascript hack coz I couldn't find a proper way to do it.
In my CGridView I used afterAjaxUpdate
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'summaryCssClass'=>'summary fr',
'id'=>'order-grid',
'afterAjaxUpdate'=>'function(id, options){ if($("#order-grid tbody tr").length == 1 && $("#order-grid tbody tr:first td").length > 1) {window.location = $("#order-grid tbody tr td:first a").attr("href");}}',
'columns' => array()
));
Hope this helps to someone.
Upvotes: 1
Reputation: 207830
public function actionAdmin() {
$this->pageTitle = Yii::app()->name . ' - Customer Support';
$model = new residence('customer');
$model->unsetAttributes();
if (isset($_GET['residence']))
$model->attributes = $_GET['residence'];
if (!Yii::app()->request->isAjaxRequest && isset($_GET['search_field'])) {
$raw = $model->customer()->getData();
if (count($raw) == 1) {
$this->redirect(array("customer/details", "id" => $raw[0]->id));
}
}
$this->render('admin', array(
'model' => $model,
));
}
where $model->customer() returns the DataProvider that the grid also uses.
Upvotes: 1