How can I display all columns in gridview without define the columns that I want to displau in view ?
In Yii2 doc,
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [ //define columns here
'id',
'name',
'created_at:datetime',
// ...
],
]) ?>
Can we just
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => '*',
]) ?>
I don't think there is such a wildcard, but you can use attributes() method on your model (if you have an instance) or array_keys(Model::getTableSchema()->columns);
Related
How can I pagination like this with yii 2 framework, demo on page https://laravel-tricks.com/
resource: https://www.yiiframework.com/doc/api/2.0/yii-widgets-linkpager
This is easy just increase number of maxButtonCount. Here is example:
This is GridView.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pager' => [
'maxButtonCount'=>40, // Set maximum number of page buttons that can be displayed
],
'columns' => [ ....
These is LinkPager.
echo LinkPager::widget([
'pagination' => $pagination,
'maxButtonCount'=>40,
.....
]);
I wanna show the rows of this list when the id_alumno of the table "reserva" is equals to id_alumno loged-in.
--table Reserva
-- GridView reserva\index
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'fecha',
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Add this in your "ReservaSearch.php" in your "search" function after the others "andFilterWhere"
$query->andFilterWhere(['id_alumno' => \Yii::$app->user->id]);
$dataProvider->query->where('reserva == id_alumno ')
You can add query in your Gridview Widget
I am using gridview , It is showing action column empty. it is not showing icon for edit, delete, view. can any one tell what is problem??
here is code
<?php
$gridColumns = [
[
'class' => 'yii\grid\SerialColumn',
],
'id',
'name',
'created',
'modified',
'modified_by_id',
['class' => 'yii\grid\ActionColumn'],
]; ?>
<?php
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'filterModel'=>$searchModel,
'columns' => $gridColumns,
'columnSelectorMenuOptions' =>
[
'style'=> 'overflow-y: scroll, height: auto;
max-height: 300px; overflow-x: hidden;',
],
'target' => ExportMenu::TARGET_SELF ,
]);
?>
<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
]);
?>
You need to add something like this:
['class' => 'yii\grid\ActionColumn',
'template' => '{delete}',
]
the "delete" should be your action name in the controller.
I found solution...In vendor folder actioncolumn.php file a line was commented ..thats why it Was showing blank column
I'm trying to hide rows from a GridView based on user permissions (RBAC).
(Yii::$app->user->can('readModel', ['model' => $model]);)
I assumed i have to add some filters to the search model, but i can't find out how i can add this filter to the query.
Maybe there is an easier solution that i haven't found yet, like adding an argument to the GridView call?
Docs don't really help me understand this specific situation either.
Thanks in advance.
a way clould be based on assign a proper class to rows using row options
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
.........
['class' => 'yii\grid\ActionColumn'],
],
'rowOptions'=>function ($model){
$class= (Yii::$app->user->can('readModel', ['model' => $model]) ? 'hide' : 'swow';
return $class;
},
As suggest the plurality of the attribute "rowOptions" is an array, lamba-function should return an array:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
.........
['class' => 'yii\grid\ActionColumn'],
],
'rowOptions'=>function ($model){
$class= (Yii::$app->user->can('readModel', ['model' => $model]) ? 'hide' : 'swow';
// HTML tag attribute class
return ['class' => $class];
},
In my yii2 project, I'm using Pjax GridView.
My index page:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'batch',
[
'attribute' => 'file_import',
'format' => 'raw',
'value'=>function ($data) {
return Html::a($data->file_import, ['/device/index', 'DeviceSearch', 'batch' => $data->batch]);
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
The link in the file_import column goes to http://localhost/index.php/device/index?1=DeviceSearch&batch=200325806610154437. But in this url, all the data is showing instead of showing only the search result. I wanted to set the file_import column as an url which will show only the search result by the provided parameter in the url.
Thank you in advance.
Change URL route to
['/device/index', 'DeviceSearch[batch]' => $data->batch]