Kartik Gridview beforeHeader

I’m wanting to display some code above the GridView and thought I could simply use the beforeHeader, but can’t seem to get it to work, can anyone offer any guidance as to what I’m doing wrong?

GridView::widget([
	'id' => 'documentGrid',
	'dataProvider' => $dataProvider,
	'tableOptions' => [
		'id' => 'table-documents',
		'class' => 'table table-bordered table-striped kv-grid-table kv-table-wrap',
	],
	'beforeHeader' => [[
		'columns' => [
			'content' => 'Testing', //$headerBtns,
			'options' => [
				'colspan' => 6, 
			]

		],
	]],
	'columns' => [
	// ...

Have you tried with only one “[” after “before header =>”?

Makes no difference (I’ve tried both ways, but the only example I could find from the author included double bracketing). According to the documentation it can accept both a string or array, and an array is supposed to be treated as HTML, which would work great in my case.

I have to work on something else in the coming days, but will come back to this at a later date as I’m sure I’m missing something obvious here.

Double the “[” before and after the content:

'beforeHeader' => [[
		'columns' => [[
			'content' => 'Testing', //$headerBtns,
			'options' => [
				'colspan' => 6, 
			]
		]],
	]],
1 Like

I have to review the documentation again to understand, but your code works perfectly! Thank you.

In each column you can have multiple rows, each one is the inner array.
So the first “[” open the row definition, the second “[” open the definition of the TD.

Try this to understand:

'beforeHeader' => [
                            [
                                'columns' => [
                                    [
                                        'content' => 'Row1 col1', //$headerBtns,
                                        'options' => [
                                            'colspan' => 6,
                                        ],
                                    ],
                                    [
                                        'content' => 'Row1 col2', //$headerBtns,
                                        'options' => [
                                            'colspan' => 6,
                                        ],

                                    ],
                                ],
                            ],[
                                'columns' => [
                                    [
                                        'content' => 'Row2 Col1', //$headerBtns,
                                        'options' => [
                                            'colspan' => 6,
                                        ],
                                    ],
                                    [
                                        'content' => 'Row2 Col2', //$headerBtns,
                                        'options' => [
                                            'colspan' => 6,
                                        ],

                                    ],
                                ],
                            ],
                        ],