如果您不想禁用对该列的排序(这也会摆脱它),那么您唯一的方法就是使用您自己的小部件。由于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
将更改放入源代码并为其他所有人解决此问题 :)