$this->widget(
'bootstrap.widgets.TbGridView',
array(
'id' => 'birthday-report-grid',
'dataProvider' => $model->search(),
'selectableRows' => 0,
'ajaxType' =>'get',
'template' => GridHelper::getTemplate(),
'type' => GridHelper::getType(),
'enablePagination' => TRUE,
'enableSorting' => TRUE,
'filter' => $model,
'pager' => GridHelper::getPager(),
'columns' => array(
array(
'header' => Yii::t('backend', 'Customer Name'),
'name' => 'fullname',
'type' =>'raw',
'value' => '$data["customer_id"] ? CHtml::link($data->getCompleteName(),array("/admin/customer/profile/".$data["customer_id"]."/dashboard")) : $data->getCompleteName()',
'filter'=>CHtml::activeTextField($model, 'fullname').CHtml::activeTextField($model, 'month', array('id'=>'Filmonth','style' => 'Display:none;')),
),
array(
'name' => 'email',
'header' => Yii::t('backend', 'Customer Email'),
),
array(
'name' => 'birthday_month',
'value' => '!empty($data->birthday_month) && $data->birthday_month > 0 ? date("F", strtotime("1-".$data->birthday_month."-1970")) : ""',
'filter' => false,
),
array(
'name' => 'primary_phone',
'header' => Yii::t('backend', 'Customer Contact'),
'filter' => false,
),
array(
'header' => Yii::t('backend', 'Total Order (To Date)'),
'value' => '$data->getNoOfOrder2()',
'htmlOptions' => array('style' => 'text-align: right'),
'footer' => '<div style="text-align: right">'.$model->getTotalOfOrder().'</div>',
),
array(
'header' => Yii::t('backend', 'Total Order Amount (To Date)'),
'value' => 'CurrencyHelper::formatPrice($data->getTotalAmountOfOrderByCustomerId2())',
'htmlOptions' => array('style' => 'text-align: right'),
'footer' => '<div style="text-align: right">'.CurrencyHelper::formatPrice($model->getGrandTotalAmountOrder()).'</div>',
),
)
)
);
WHat i want is how to get sort value (Example: sort=fullname) what i want is "fullname"
i mean when i click column sorting on Customer Fullname , i can get the sort value using Jquery
Example image:
When Click sorting on "Customer Fullname" i need get sorting value (sort="VALUE")
Please help me thanks
controller:
public function actionItem($textdata){
$dataProvider = new CActiveDataProvider('Mytest', array(
'criteria' => array(
'condition' => 'type="'.$textdata.'"',
),
));
$bleble = $textdata;
$this->render('Item', array(
'dataProvider' => $dataProvider,
'bleble' => $bleble,
));
}
view:
$bleble = $bleble;
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'sample_id',
'dataProvider' => $dataProvider,
'columns' => array(
array(
'header' => 'id',
'name' => 'id',
'value' =>'$data->id',
'type' =>'raw',
"value" => function($data){
echo "text".$data->id;
},
),
NEED !! :
$bleble = $bleble;
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'sample_id',
'dataProvider' => $dataProvider,
'columns' => array(
array(
'header' => 'id',
'name' => 'id',
'value' =>'$data->id',
'type' =>'raw',
"value" => function($data){
echo $bleble.$data->id;
},
),
error :
PHP notice
Undefined variable: bleble
need to download the text of the link that is how I controller ($ text) $ text is the one I have to write out the table but does not work when it is a variable, normal text works for example echo "text".$data->id;
You can do it like this:
"value" => function($data) use ($bleble){
return $bleble.$data->id;
}
Hope this works for you
I am using CGridView in Yii which is listing results with some of relations from other models
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter' => $model,
'columns' => array(
array(
'name' => 'user.name',
'header' => Yii::t('app', 'User'),
'value' => '!isset($data->user->name) ? Yii::t("app", "Unknown user") : $data->user->name',
'type' => 'raw',
'filter' => CHtml::activeTextField($model, 'keyName'),
),
array(
'name' => 'visitor.company',
'header' => Yii::t('app', 'Company'),
'value' => 'isset($data->visit->visitor->company) ? $data->visit->visitor->company : (isset($data->rfid->rfid) ? Yii::t("app", "Company 1") : Yii::t("app", "Unknown company"))',
'type' => 'raw',
'filter' => CHtml::activeTextField($model, 'visitorCompany'),
),
array(
'name' => 'pass_id',
'header' => Yii::t('app', 'Pass'),
'value' => '!isset($data->pass_id) ? Yii::t("app", "Massing pass") : "<span class=\"label label-primary\">" . $data->pass_id . "</span>"',
'type' => 'raw',
),
),
)); ?>
and there is isset() condition which checks if relation exists (otherwise an error occurs)
But now I am looking for a way to filter those results which. For example to write "Unknown" in the filter to get the results without relations in the other table or "Company" to get those without some relation but with another existing relation
I'm using yii for my web application. In one of my view I have CGridView and dataprovider is Mail model. In this model I have relation with with 3 other models. In the grid I show cols from three models. How can I filter the CGridView?
UPDATE:
<?php $dialog = $this->widget('ext.ecolumns.EColumnsDialog', array(
'options'=>array(
'title' => 'Layout settings',
'autoOpen' => false,
'show' => 'fade',
'hide' => 'fade',
),
'htmlOptions' => array('style' => 'display: none'), //disable flush of dialog content
'ecolumns' => array(
'gridId' => 'mails-grid', //id of related grid
'storage' => 'session', //where to store settings: 'db', 'session', 'cookie'
'fixedLeft' => array('CCheckBoxColumn'), //fix checkbox to the left side
'model' => $dataprovider, //model is used to get attribute labels
'columns'=>array(
array(
'name'=>'mailTemplate.name',
'filter'=>CHtml::activeTextField($dataprovider, 'mailTemplate'),
),
'sendDate',
array(
'name'=>'mailTemplate.subject',
'filter'=>CHtml::activeTextField($dataprovider, 'mailTemplate'),
),
array(
'name'=>'client.email',
'filter'=>CHtml::activeTextField($dataprovider, 'client'),
),
array(
'name'=>'client.name',
'filter'=>CHtml::activeTextField($dataprovider, 'client'),
),
array(
'name'=>'operator.username',
'filter'=>CHtml::activeTextField($dataprovider, 'operator'),
),
array(
'name'=>'status',
'value'=>array('MailHelper', 'getEmailStatus'),
'filter'=> CHtml::activeDropDownList($dataprovider, 'status', Mail::getEmailStatuses()),
),
array(
'class'=>'CButtonColumn',
'template'=>'{update}',
'buttons'=>array(
'update' => array(
'url'=>'$this->grid->controller->createUrl("/email/editTemplate", array("templateId"=>$data->id))',
),
),
)
),
)
));
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'mails-grid',
'dataProvider'=>$dataprovider->search(),
'columns' => $dialog->columns(),
'filter' => $dataprovider,
'template' => $dialog->link()."{summary}\n{items}\n{pager}",
)); ?>
I have Restaurant, City, Country and User models with relations between them.
Model:
public function search() {
$criteria=new CDbCriteria;
$criteria->together = true;
$criteria->with= array('xCountry','xCity','User');
$criteria->compare('Id',$this->Id,true);
$criteria->compare('Restaurant.Name',$this->Name,true);
$criteria->addSearchCondition('xCountry.Name',$this->Country);
$criteria->addSearchCondition('xCity.Name',$this->City);
$criteria->compare('Zip',$this->Zip,true);
$criteria->compare('Address',$this->Address,true);
$criteria->compare('Description',$this->Description,true);
$criteria->compare('Restaurant.Active',$this->Active,true);
$criteria->addSearchCondition('User.Username',$this->Owner);
$criteria->compare('Lat',$this->Lat);
$criteria->compare('Lon',$this->Lon);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
View:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'restaurant-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'Id',
'Name',
'Zip',
'Address',
'Active',
array(
'name' => 'User.Username',
'header' => 'Username',
'filter' => CHtml::activeTextField($model, 'Owner'),
'value' => '$data->User->Username',
),
array(
'name' => 'xCountry.Name',
'header' => 'Country',
'filter' => CHtml::activeTextField($model, 'Country'),
'value' => '$data->xCountry->Name',
),
array(
'name' => 'xCity.Name',
'header' => 'City',
'filter' => CHtml::activeTextField($model, 'City'),
'value' => '$data->xCity->Name',
),
array(
'class'=>'CButtonColumn',
),
),
));
I hope this can help you.
UPDATE:
What if you try something like this:
...
'columns'=>array(
'mailTemplate.name',
'sendDate',
'mailTemplate.subject',
'client.email',
...
UPDATE #2:
Prepare yourself this will be a bit dirty.
Let's say we've got two classes, A and B. B belongs to A.
B's got a property, let's say "color" and we want to display it in our grid where we list the "A"s.
The first thing you have to do is, manually create a property to your data provider class (what is "A").
This property will be "colorOfB", so you have to add "public $colorOfB;" to your model A.
Add criteria for this property:
$criteria->compare('B.color',$this->colorOfB,true);
Add the column to the grid:
array(
'name' => 'B.color',
'header' => 'Color of B',
'filter' => CHtml::activeTextField($model, 'colorOfB'),
'value' => '$data->B->color'),
The final thing is to set this property manually in A's controller:
$modelA = new A('search');
$modelA->colorOfB = $_GET['A']['colorOfB'];
this will set select list
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'avto-ugon-grid',
'dataProvider'=>$model_data,
'filter'=>$model,
'columns'=>array(
'id',
array(
'name' => 'time',
'value' => 'date("d/m/Y", $data->time)',
'type' => 'html',
),
array(
'name' => 'nomer',
'value' => '$data->nomer',
'type' => 'html',
),
array(
'name' => 'id_marka',
'value' => '$data->idMarka->mark',
'type' => 'html',
'filter'=> CHtml::listData(AvtoUgon::model()->with('idMarka')->findAll(array('group'=> 'id_marka', 'order'=> 'idMarka.mark')), 'id_marka', 'idMarka.mark'),
),
array(
'name' => 'id_model',
'value' => '$data->idModel->model',
'type' => 'html',
'filter'=> CHtml::listData(AvtoUgon::model()->with('idModel')->findAll(array('group'=> 'id_model', 'order'=> 'idModel.model')), 'id_model', 'idModel.model'),
),
array(
'name' => 'color',
'value' => $data->color,
'type' => 'raw',
),
array(
'name' => 'id_street',
'value' => '$data->idStreet->street',
'type' => 'html',
),
array(
'name' => 'publish',
'value' => 'CHtml::link($data->publish ? "Опубликовано" : "Не опубликовано", Yii::app()->controller->createUrl("publish", array("id" => $data->id)))',
'type' => 'html',
),
/*'id_street',
'nomer',
*/
array(
'class'=>'CButtonColumn',
),
),
));
I am new to Yii framework and just started to work on an existing website. I have a listing page and my requirement was to add a new field 'review_date_time' and I could managed to display it in listing. Now my question is how to change the format of the date and how to show a white space if date is not there in table field.Right now it is displaying 0000-00-00 00:00:00 if no date is there.
My code for listing
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'series-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
array('header' => 'Category', 'name' => 'category.title'),
'exam_year',
'title',
'review_date_time',
array(
'class' => 'CButtonColumn',
),
),
));
If it is showing 0000-00-00 00:00:00 then it means that, that value is the default value in the db table, hence you'll have to use the value property of CDataColumn:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'series-grid',
'dataProvider' => $model->search(),
'filter' => $model,
// 'nullDisplay'=>'',
'columns' => array(
array('header' => 'Category', 'name' => 'category.title'),
'exam_year',
'title',
// 'review_date_time',
array(
'name'=>'review_date_time',
'value'=>'$data->review_date_time=="0000-00-00 00:00:00"?"":$data->review_date_time'
)
array(
'class' => 'CButtonColumn',
),
),
));
Or try the nullDisplay property of CGridView (if you are storing null and overriding afterFind to format null as 0000-00-00 00:00:00):
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'series-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'nullDisplay'=>'',
'columns' => array(
array('header' => 'Category', 'name' => 'category.title'),
'exam_year',
'title',
'review_date_time',
array(
'class' => 'CButtonColumn',
),
),
));