1

在 YiiBootstrapTbGridView中,列标题默认使用 ^ 进行排序。

\protected\extensions\bootstrap\widgets\TbDataColumn.php它在第 28 行的文件中提到,例如

if ($sort->resolveAttribute($this->name) !== false)
    $label .= '<span class="caret"></span>';

因此,它显示为标签旁边带有向下箭头的列标题。

我希望我的列标题旁边没有插入符号,但我不想在源小部件中更改它,因为这意味着我们将来更新扩展时会遇到问题。

有没有办法用TbGridView小部件本身的属性来做到这一点?

4

2 回答 2

1

如果您不想禁用对该列的排序(这也会摆脱它),那么您唯一的方法就是使用您自己的小部件。由于TbDataColumn某些原因,该类被硬编码到 TbGridView 中。(你可以在这里看到

您可以从 继承TbGridView,覆盖该函数并将其替换为调用您的EDataColumn类的函数。然后你可以对ETbDataColumn继承做同样的事情TbDataColumn,只覆盖你需要的函数。

例如

Yii::import('Bootstrap.widgets.TbGridView');
Yii::import('ext.widgets.ETbDataColumn');

/**
 * Bootstrap grid data column.
 */
class ETbGridView extends TbGridView
{

    public function createDataColumn($text)
    {
         if (!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/', $text, $matches))
                    throw new CException(Yii::t('zii', 'The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));

            $column = new ETbDataColumn($this);
     ......

但是,如果您有回馈的心情,您可以随时更改 YiiBootstrapTbGridView以使用参数来确定要使用的列类,并在此处向 YiiBootstrap 提交拉取请求:https ://bitbucket.org/Crisu83/yii-bootstrap /pull-requests 将更改放入源代码并为其他所有人解决此问题 :)

于 2013-01-11T08:36:33.333 回答
0

我知道我正在回答一个老问题,但希望这会帮助其他人寻找解决方案。以下是我解决此问题的方法:

假设最初的问题是关于在未用于排序的列上隐藏插入符号,则以下 css 更改应该有助于在不更改扩展源代码的情况下实现结果。我认为在所有可排序的列上显示插入符号是一个错误,相反插入符号应该只出现在用于对当前结果集进行排序的列上,并且它应该具有正确的方向。

.grid-view thead .caret {
    display: none;
}

.grid-view thead .asc .caret,
.grid-view thead .desc .caret {
    display: inline-block;
}

.grid-view thead .asc .caret {
    border-top: none;
    border-bottom: 4px solid;
}
于 2014-10-30T13:22:08.273 回答