我在很长一段时间内面临一个麻烦的情况,没有任何明确的解决方案。问题是我有一个gridview,它显示产品信息和5d,6m和12m的投资回报以及另一个名为total profitable%的列。此总盈利%列分别针对每个月计算,并存储在数据库的单独列中。
现在的问题是,如何使这个名为total profitable%的列显示当前用户正在排序的roi月的信息。因此,如果用户对5d ROI列进行排序,则总盈利百分比将重新计算为5天的总盈利百分比。如果用户对6米ROI列进行排序,则总盈利百分比将再次重新计算为6米,依此类推。我一直试图找到一种方法来实现这一点,通过将所有月份的总盈利%列的“可见”属性设置为false,除了用户正在对ROI列进行排序的那一行,但它不在所有
这是有问题的gridview。
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'product-news-grid-'. $id,
'itemsCssClass' => 'table table-striped',
'htmlOptions' => array(
'class' => 'news-datagrid',
),
'dataProvider' => $dataProvider->searchProductNewsSymbol($name, $headlines, $publish_date),
'filter' => $dataProvider,
'enableHistory' => false,
'ajaxUpdate' => 'product-news-grid-'. $id,
'ajaxUrl' => Yii::app()->createUrl('/productDetails/AjaxUpdateProductNews'),
'pager' => array(
'header' => '',
'cssFile' => false,
'maxButtonCount' => 5,
'selectedPageCssClass' => 'active',
'hiddenPageCssClass' => 'disabled',
'firstPageCssClass' => 'previous',
'lastPageCssClass' => 'next',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
),
'summaryCssClass' => 'label label-warning',
'columns' => array(
array(
'name' => 'name',
'header' => 'Name',
'value' => function($data) {
return '<div class="product-name"> <a target="_blank" href="'. $data->id .'" > '. $data->name .'</a></div>';
},
'type' => 'raw',
),
array(
'name' => 'headlines',
'header' => 'Headlines',
'value' => function($data) {
return '<div class="product-news"> <a target="_blank" href="'. $data->link .'" > '. $data->headlines .'</a></div>';
},
'type' => 'raw',
),
array(
'name' => 'publish_date',
'header' => 'Date',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->publish_date .'</span>';
},
'type' => 'raw',
),
array(
'name' => 'fived_roi',
'header' => '5d ROI',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->fived_roi .'</span>';
},
'type' => 'raw',
),
array(
'name' => 'sixm_roi',
'header' => '6m ROI',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->sixm_roi .'</span>';
},
'type' => 'raw',
),
array(
'name' => 'twlm_roi',
'header' => '12m ROI',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->twlm_roi .'</span>';
},
'type' => 'raw',
),
array(
'name' => 'fived_profit',
'header' => 'Total Profit %',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->fived_profit .'%</span>';
},
'type' => 'raw',
),
array(
'name' => 'sixm_profit',
'header' => 'Total Profit %',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->sixm_profit .'%</span>';
},
'type' => 'raw',
'visible' => false
),
array(
'name' => 'twlm_profit',
'header' => 'Total Profit %',
'value' => function($data) {
return '<span class="news-pub-date">'. $data->twlm_profit .'%</span>';
},
'type' => 'raw',
'visible' => true
),
)
));
?>
我尝试通过将单击处理程序附加到表列标题,并渲染具有Total profitable%列中任何一个的不同视图来实现此功能。但它不起作用,导致排序不起作用,整个网格在渲染不同之后崩溃。
所以任何人都可以指出我如何达到预期效果的正确方向。我将不胜感激任何帮助。
谢谢, Maxx
修改
以下是searchProductNewsSymbol()
的代码public function searchProductNewsSymbol ( $name ,
$headlines = NULL ,
$publish_date = NULL ) {
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria ;
$criteria->select = 'name, publish_timestamp, publish_date, headlines, link, last_updated';
$criteria->group = 'headlines';
$criteria->compare ( 'name' ,
$name ,
true ) ;
if ( isset ( $headlines ) || $headlines != "" ) {
$criteria->compare ( 'headlines' ,
$headlines ,
TRUE ,
'AND' ) ;
}
if ( isset ( $publish_date ) || $publish_date != "" ) {
$criteria->compare ( 'publish_date' ,
$publish_date ,
TRUE ,
'AND' ) ;
}
return new CActiveDataProvider ( $this ,
array (
'criteria' => $criteria ,
'sort' => array (
'defaultOrder' => 'publish_date desc' ,
) ,
) ) ;
}
答案 0 :(得分:0)
点击按钮,尝试这样做。
$.fn.yiiGridView.update("<id of CGridView>");