How to remove summary and sorter for a particular grid view in Yii2. In Yii1.1 we can do that by setting the template property. In yii2 how to achieve this?
Asked
Active
Viewed 5.8k times
5 Answers
47
To change only summary
option, you can use:
'summary' => "{begin} - {end} {count} {totalCount} {page} {pageCount}",
Then, if you want to empty summary
set with empty string value like:
'summary'=> "",
and to change layouts you can use:
'layout'=> "{summary}\n{items}\n{pager}"
Then, if you want to empty layouts
set layout with empty string value like:
'layout'=> "",
So, for sample, i think bellow sample code can be help know how to change and custome GridView
table in Yii 2:
<?= \yii\grid\GridView::widget([
'id' => 'table',
'dataProvider' => $dataProvider,
'layout'=>"{sorter}\n{pager}\n{summary}\n{items}",
'summary' => "Showing {begin} - {end} of {totalCount} items",
'tableOptions' => ['class' => 'table table-bordered table-hover'],
'rowOptions' => function ($model, $key, $index, $grid) {
return [
'style' => "cursor: pointer",
'onclick' => 'location.href="'
. Yii::$app->urlManager->createUrl('test/index')
. '?id="+(this.id);',
];
},
'columns' => [
[
'class' => 'yii\grid\SerialColumn',
'contentOptions' => ['style' => 'width: 20px;', 'class' => 'text-center'],
],
[
'class' => 'yii\grid\DataColumn',
'attribute' => 'date',
'headerOptions' => ['class' => 'text-center'],
'label' => 'Date',
'contentOptions' => ['style' => 'width: 130px;', 'class' => 'text-center'],
],
'template' => '{view}',
'buttons' => [
'view' => function ($url, $model) {
return \yii\helpers\Html::a('<div class="text-center"><em data-toggle="tooltip"
data-placement="top" title="more detail"
class="fa fa-external-link-square text-warning"></em></div>',
(new yii\grid\ActionColumn())->createUrl('test/index', $model, $model['id'], 1), [
'title' => Yii::t('yii', 'view'),
'data-method' => 'post',
'data-pjax' => '0',
]);
},
]
],
],
]); ?>

Sajjad Dehghani
- 640
- 1
- 6
- 15
-
Error- Undefined variable: count. $dataProvider->count fixed that for me. – 111 Dec 24 '16 at 18:44
-
'count' come from controller that passed on view render, You can remove 'count' variable. – Sajjad Dehghani Dec 26 '16 at 16:05
11
Got it.By setting the layout property,we can achieve it.
'layout'=>"{summary}\n{items}\n{pager}"

Dency G B
- 8,096
- 9
- 47
- 78
6
if you want only grid items use 'layout'=>"{items}"
if you want only summary use 'layout'=>"{summary}"
if you want only sorter use 'layout'=>"{pager}"

Ajey
- 7,924
- 12
- 62
- 86
0
Set the paremeter summaryText
to empty string:
array(
'summaryText' => '',
'dataProvider' => $model->search(),
...

arogachev
- 33,150
- 7
- 114
- 117

Developerium
- 7,155
- 5
- 36
- 56
0
[
'class' => 'yii\grid\ActionColumn',
'buttons' =>
[
'update'=>function($url,$model,$key)
{
return Html::a( "update" , $url ); //use Url::to() in order to change $url
},
'view'=>function($url,$model,$key)
{
return Html::a( "update" , $url ); //use Url::to() in order to change $url
},
'delete'=>function($url,$model,$key)
{
return Html::a( "update" , $url, [
'class' => 'btn btn-lg btn-primary',
'data' => [
'method' => 'post',
'params' => ['derp' => 'herp'], // <- extra level
],
] ); //use Url::to() in order to change $url
}
],
'template' => '<div class="column-buttons">
<span>{update}</span>
<span>{view}</span>
<span>{delete}</span>
</div>',
'header' => 'Actions'
]

Ziya Vakhobov
- 465
- 4
- 10