在我的 yii2 项目中,我使用下拉菜单在我的 gridview 的 actionColumn 中显示操作。问题是,当数据行数少于 3 或 4 时,下拉列表会完全显示(只是足够的空间来显示所有操作)-参见图 1。但是当有足够的行和空间时,下拉菜单正确显示(见图 2)。
我尝试通过更改 z-index 的值来使用 CSS 修复它,但没有运气。如果有人能提供帮助,我将不胜感激。
图片1
这是我的代码:
['class' => 'yii\grid\ActionColumn',
'contentOptions' => ['style' => 'width:10%;'],
'header'=>'Actions',
'template' => '{all}',
'buttons' => [
'all' => function ($url, $model, $key) {
return ButtonDropdown::widget([
'encodeLabel' => false, // if you're going to use html on the button label
'label' => 'Choisir',
'dropdown' => [
'encodeLabels' => false, // if you're going to use html on the items' labels
'items' => [
[
'label' => \Yii::t('yii', '<i class="icon-search4"></i> Voir'),
'url' => ['view', 'id' => $key],
],
[
'label' => \Yii::t('yii', '<i class="icon-pencil5"></i> Modifier'),
'url' => ['update', 'id' => $key],
'visible' => true,
],
[
'label' => \Yii::t('yii', '<i class="icon-list"></i> Valider'),
'url' => ['validate', 'id' => $key],
'visible' => true, // if you want to hide an item based on a condition, use this
],
/*[
'label' => \Yii::t('yii', "<i class='icon-city'></i> Voir le vendeurAgence"),
'url' => ['annonces', 'agence_id' => $model->vendor_id],
'visible' => true, // if you want to hide an item based on a condition, use this
],*/
[
'label' => \Yii::t('yii', '<i class="icon-bin"></i> Supprimer'),
'linkOptions' => [
'data' => [
'method' => 'post',
'confirm' => \Yii::t('yii', 'Voulez-vous vraiment supprimer cette vente ?'),
],
],
'url' => ['delete', 'id' => $key],
'visible' => true, // same as above
],
],
'options' => [
'class' => 'dropdown-menu-right', // right dropdown
],
],
'options' => [
'class' => 'btn-default',
'style' => 'padding-left: 5px; padding-right: 5px;', // btn-success, btn-info, et cetera
],
'split' => true, // if you want a split button
]);
},
],
图二