I have an attribute, idC, which may contain any positive integer number.
So, If idC has values like 2,3, and so on such that 3 comes 4 times and 2 comes 2 times.
Now, I want to list out data values with only idC=3 for one page
and idC=2 for another page and so on.
But how to do this.
Here is the listing code:
<?php
$this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'Subjects-grid',
'dataProvider'=>$model->search(),
'type'=>'striped bordered condensed',
'template'=>'{summary}{items}{pager}',
'columns'=>array(
array('header'=>'<a>S.N.</a>',
'value'=>'$data->id_subjects',
'htmlOptions'=>array('width'=>'70px'),
),
'idC=$idC',
array(
'header'=>'<a>Subject</a>',
'value'=>'$data->subject',
),
'staff_type',
'sub_subject',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
'header'=>'<a>Actions</a>',
'template' => '{view} {update}',
'buttons' => array(
'view' => array(
'label'=> 'View',
'options'=>array(
'class'=>'btn btn-small view'
) ),
'update' => array(
'label' => 'Update',
'options' => array(
'class' => 'btn btn-small update'
)
),
),
'htmlOptions'=>array('nowrap'=>'nowrap'),
)
),
)); ?>
and here's the view page.
Related
I have created Dataprovider in controller and pass it to view file. It display correct Data. There are total 7 columns to display.
But only on 2 fields sorting is not working and throwing ERROR-500.
In controller File, my Code is :
$OutboundRatecardDetails_data = OutboundRatecardDetails::model()->findAllByAttributes(array('orc_id'=>$orc_id));
$pageSize = 10;
if(isset($_GET['pageSize']))
{
$pageSize = $_GET['pageSize'];
Yii::app()->user->setState('pageSize', (int)$_GET['pageSize']);
unset($_GET['pageSize']);
}
$dataProvider=new CArrayDataProvider($OutboundRatecardDetails_data, array(
'id'=>'orcd_id',
'sort'=>array(
'attributes'=>array(
'orcd_id', 'des_id', 'orcd_duration','orcd_rate','orcd_grace_duration','orcd_description'
),
),
'pagination'=>array(
'pageSize'=>$pageSize,
),
'keyField'=>'orcd_id',
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
In admin.php view file, my code is :
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id'=>'Outbound-rate-card-details-grid',
'dataProvider' =>$dataProvider,
'itemsCssClass' =>'table table-bordered table-striped table-condensed',
'pagerCssClass' =>'dataTables_paginate paging_bootstrap pagination',
'htmlOptions' =>array('class'=>'adv-table'),
'columns'=>array(
'des_id'=>array(
'name'=>'des_id',
'header'=>'Destination',
'value' => '(!empty($data->rel_destination->des_prefix) ? $data->rel_destination->des_prefix : "")',
),
array(
'name'=>'orcd_grace_duration',
'header'=>'Grace Duration',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_duration',
'header'=>'Incr. Duration',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_rate',
'header'=>'Incr. Rate',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_min_duration',
'header'=>'Min. Duration',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_min_rate',
'header'=>'Min. Rate',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
array(
'name'=>'orcd_description',
'header'=>'Rate Description',
'htmlOptions' => array('style' => 'max-width:150px; white-space:normal;word-break:break-all;'),
),
),
)); ?>
When I try to sort on 2nd and 3rd field (orcd_grace_duration,orcd_duration), it throws error. Error screenshot is also attached. Other than these 2 fields, sorting is perfectly working.
This issue occurs when CArrayDataProvider's columns having same values.
Try using CActiveDataPrider instead.
You just need to change code in your controller like below:
$criteria = new CDbCriteria;
$criteria->compare('orc_id',$orc_id,true);
$dataProvider = new CActiveDataProvider('OutboundRatecardDetails', array(
'criteria'=>$criteria,
'sort' => array(
'defaultOrder' => 'orc_id desc',
),
'pagination'=>array(
'pageSize'=>$pageSize,
),
));
there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])
I want show pagination before gridview content. i tried renderPager() I cannot get widget object call the method
code here...
$gridview = $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$expirations,
'id'=>'image-grid-list',
'itemsCssClass'=>'table collections',
'ajaxUpdate'=>true,
'template'=>'{items}{summary}',
'pager'=>array(
'class'=>'CLinkPager',
'header'=>'',
),
'columns'=>array
(
array(
'class'=>'CCheckBoxColumn',
'selectableRows' => null,
'name'=>'image_id',
"value"=>'$data->image_id',
"id"=>"expirations",
"htmlOptions"=>array("style"=>"width:30px;")
),
array(
'name'=>'',
'type'=>'html',
'value'=>'
(!empty($data->image_title))?CHtml::image("/".Yii::app()->params["imagePath"]."/".$data->catalog->catalog_title."/thumb_".$data->image_title,"",array()):"no image"',
'header'=>''
),
array(
'name'=>'image_title',
'type'=>'raw',
'value'=>'CHtml::link($data->catalog->catalog_title."/".$data->image_title,"javascript:void(0);")."<br>#".$data->image_id."<br/><br/> Number of light boxes ".$data->collection_count." <br/><br/> Number of downloads ".$data->downloaded_count ',
'header'=>'Title'
),
array( // display 'author.username' using an expression
'name'=>'copyright_expiration_date',
'type'=>'raw',
'value'=>'(!empty($data->copyright_expiration_date))?date("m-d-Y",$data->copyright_expiration_date):"-"',
'header'=>'Rights expiration date'
),
array( // display 'author.username' using an expression
'name'=>'copyright_type',
'type'=>'raw',
'value'=>'$data->copyright_type',
'header'=>'Rights'
),
array( // display 'author.username' using an expression
'name'=>'',
'value'=>'$data->usage_and_terms',
'header'=>'Usage and terms'
),
array( // display 'create_time' using an expression
'name'=>'photographer_name',
'value'=>'$data->photographer_name',
'type'=>'raw',
'header'=>'Photographer name'
),
),
),true);
$gridview->renderPager();
I cannot call the method .. I want create widget object , call renderContent, renderPager etc
use template attribute.
'template' => '{pager}{items}{summary}',
eg.,
$gridview = $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$expirations,
'id'=>'image-grid-list',
'itemsCssClass'=>'table collections',
'ajaxUpdate'=>true,
'template' => '{pager}{items}{summary}',
'pager'=>array(
'class'=>'CLinkPager',
'header'=>'',
),
'columns'=>array
(
......
I used from CGridView in framework Yii, I want when I click view button , it is opened in a new window
how can I add of "_new" of target ?
Add 'options' => array('target'=>'_new') to CButtonColumn configuration array in CGridView
array(
'class'=>'zii.widgets.grid.CButtonColumn',
'template' => '{view}',
'buttons'=>array(
'view' => array(
'url' => '', // view url
'options' => array('target' => '_new'),
),
),
),
You can provide the html properties by using 'options' property.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('class' => 'newWindow'),
),
),
),
),
));
?>
But, Opening a new window is browser dependent. With target="_blank" and target="_new" link will be opened in new tab in Mozilla, But in IE you will get new window. So user javascript to generate new window.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('class' => 'newWindow'),
),
),
),
),
));
?>
Keep this jQuery in your .js file
<script>
$(document).ready(function()
{
$(".newWindow").click(function(e)
{
e.preventDefault();
var url=$(this).attr('href');
window.open(url, "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=100, left=100, width=1020, height=500");
});
});
</script>
You can use this
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('target' => '_blank'),
),
),
),
),
));
?>
I want to disable the update button from CGridView Table. I don't know how to do it. Just disable the update button, not delete the function of update. Anybody know how to do it? Thanks
'columns' => array(
// All your columns here
// ...
array(
'template' => '{view}{delete}',
'class' => 'CButtonColumn',
),
),
It's enough :)
EDIT: above solution removes the button. The following disable it (by removing the link):
'columns' => array(
// All your columns here
// ...
array(
'template' => '{view}{update}{delete}',
'class' => 'CButtonColumn',
'buttons' => array(
'update' => array(
'url' => ''
),
),
),
You have to change the 'template' property of your CButtonColumn.
The default value for 'template' is '{update}{view}{delete}'.
So you have to do this:
array(
'class' => 'CButtonColumn',
'template' => '{view}{delete}',
),