0

I'm trying to set up a new grid view in yii booster while passing a variable through at the start of the view to sort the formatting.

I presume I am not passing the variable properly by this line

$gridColumns = $this->widget('booster.widgets.TbGridView', array(

How would I go about using this variable? I can create a new form array okay not using yiibooster but with the widget activated it no longer likes the variable name

The issue is I'm getting the error in the title of the post.

$gridColumns = $this->widget('booster.widgets.TbGridView', array(
    'id' => 'delegate-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
        //  'id',
        array(
            'name' => 'forename',
            'type' => 'raw',
            'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
        ),
        'surname',
//        'facilities',
        //  'telephone',
        //  'address_id',
        /*
          'logo_path',
         */
        array(
            'class' => 'booster.widgets.TbButtonColumn',
        ),
    ),
));

$groupGridColumns = $gridColumns;
$groupGridColumns[] = array(
    'name' => 'firstLetter',
    'value' => 'substr($data->surname, 0, 1)',
    'headerHtmlOptions' => array('style' => 'display:none'),
    'htmlOptions' => array('style' => 'display:none')
);

$this->widget('booster.widgets.TbGroupGridView', array(
    'id' => 'user-grid',
    'type' => 'striped bordered condensed highlight',
    //'template' => "{items}",
    'dataProvider' => $model->search(),
    'filter' => $model,
    'extraRowColumns' => array('firstLetter'),
    'extraRowExpression' => '"<b style=\"font-size: 3em;  color: #333;\">".substr($data->surname, 0, 1)."</b>"',
    'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
    'columns' => $groupGridColumns,

));
Alex
  • 673
  • 3
  • 9
  • 22

1 Answers1

0

It is because you are giving an object of type CGridView to TbGroupGridView as parameter.

$groupGridColumns = $gridColumns;

You are putting an object of type TbGridView($gridColumns) in $groupGridColumns and then give it to your TbGroupGridView, but TbGroupGridView columns property expects its value be an array of arrays(definition of columns) and so throws new exception when in the first cell of $groupGridColumns find an object. You do not need the first part and with some changes, your code should work fine with filtering enabled.

$this->widget('booster.widgets.TbGroupGridView', array(
    'id' => 'user-grid',
    'type' => 'striped bordered condensed highlight',        
    'dataProvider' => $model->search(),
    'filter' => $model,
    'extraRowColumns' => array('firstLetter'),
    'extraRowExpression' => '"<b style=\"font-size: 3em;  color: #333;\">".substr($data->surname, 0, 1)."</b>"',
    'extraRowHtmlOptions' => array('style' => 'padding:10px;text-align: center;'),
    'columns' => array(
           array(
                 'name' => 'forename',
                 'type' => 'raw',
                 'value' => 'CHtml::link($data->forename, array("user/view", "id" => $data->id))',
           ),
           'surname',
           array(
                 'name' => 'firstLetter',
                 'value' => 'substr($data->surname, 0, 1)',
                 'headerHtmlOptions' => array('style' => 'display:none'),
                 'htmlOptions' => array('style' => 'display:none')
           )        
           array(
                 'class' => 'booster.widgets.TbButtonColumn',
           ),
    )
));
Mohamad Eghlima
  • 970
  • 10
  • 23