我想自定义HTML属性添加到cgridview从按钮的dataProvider,进出口使用引导Yii引导bootstrap.widgets.TbButtonColumn
我试过了
'pbs_id'=>'{$data->pbs_id}',
和
'pbs_id'=>'{$data["psp_id"]}',
但它以字符串形式返回
$this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped bordered condensed',
'dataProvider'=>$db_slabs_data,
'template'=>"{items}",
'columns'=>array(
array('name'=> 'pbs_id', 'header'=>'Slab Id'),
array('name'=> 'pbs_name', 'header'=>'Slab Name'),
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>"{update}",
'updateButtonUrl'=>'Yii::app()->createUrl("", array("pbs_id"=>$data["pbs_id"]))',
'buttons'=>array
(
'update' => array
(
'label'=> Yii::t('common', 'LBL_UPDATE'),
'icon'=>'icon-pencil',
'url'=>'Yii::app()->createUrl("", array("pbs_id"=>$data["pbs_id"]))',
'options'=>array(
'pbs_id'=>'{$data["psp_id"]}',
),
),
),
),
),
));
广告的结果是:
<a href="" pbs_id=1" rel="tooltip" title="" pbs_id="{$data->pbs_id}" data-original-title="Update"><i class="icon-pencil"></i></a>
我该怎么做。
谢谢
我通过以下方式解决了我的问题:
在此文件/protected/extensions/bootstrap/widgets/TbButtonColumn.php内,有一种方法renderButton()
我重写此方法来呈现按钮的其他html属性:
protected function renderButton($id, $button, $row, $data) {
if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row' => $row, 'data' => $data)))
return;
$label = isset($button['label']) ? $button['label'] : $id;
$url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row)) : '#';
$options = isset($button['options']) ? $button['options'] : array();
/* added to render additional html attribute */
if (isset($button['options']) AND !(empty($button['options']))) {
foreach ($button['options'] as $key => $value) {
if (preg_match('#\$(data|row)#', $value)) {
$options["$key"] = $this->evaluateExpression($button['options'][$key], array('data' => $data, 'row' => $row));
} else {
$options["$key"] = $value;
}
}
}
/* end */
if (!isset($options['title']))
$options['title'] = $label;
if (!isset($options['rel']))
$options['rel'] = 'tooltip';
if (isset($button['icon'])) {
if (strpos($button['icon'], 'icon') === false)
$button['icon'] = 'icon-' . implode(' icon-', explode(' ', $button['icon']));
echo CHtml::link('<i class="' . $button['icon'] . '"></i>', $url, $options);
}
else if (isset($button['imageUrl']) && is_string($button['imageUrl']))
echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
else
echo CHtml::link($label, $url, $options);
}
并在网格内
'buttons'=>array
(
'update' => array
(
'label'=> Yii::t('common', 'LBL_UPDATE'),
'icon'=>'icon-pencil',
'url'=>'Yii::app()->createUrl("", array("pbs_id"=>$data["pbs_id"]))',
'options'=>array(
'id'=>'$data["id"]',
'new_attribute'=> '$data["your_key"]',
),
),
),
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句