How can put an ActiveForm in a gridview column? The following is the code I made: I tried to render the page such that it includes the active form which I need.
'columns' => [
[ 'format' => 'html',
'value'=> function($data) { return Html::img($data->imageurl) . " <p class='feedback-username'>" . $data->username . "</p>"; },
'contentOptions'=>['style'=>'width: 30px; height: 30px'],
],
[ 'format' => 'raw',
'value' => function($model) { return "<p class='feedback'>". $model->KOMENTAR ."</p><br><p class='feedback-date'>". $model->TANGGAL ."</p><hr><div id='replay-". $model->ID_KOMENTAR."'><ul></ul></div>";},
],
[ 'format' => 'raw',
'contentOptions'=>['style'=>'width: 5px;'],
'value' => function($model) {
if($model->id == Yii::$app->user->identity->id) {
return Html::a('<i class="glyphicon glyphicon-share-alt"></i>',null,['id'=> 'replay-to-'. $model->ID_KOMENTAR ]).' '.
Html::a('<i class="glyphicon glyphicon-pencil"></i>', ['update', 'id' => $model->id]).' '.
Html::a('<i class="glyphicon glyphicon-trash"></i>', ['delete', 'id' => $model->id], ['data' => ['confirm' => 'Do you really want to delete this element?','method' => 'post']]);
}
return Html::a('<i class="glyphicon glyphicon-share-alt"></i>',['feedback', 'id' => $model->id],['id'=> 'replay-to-'. $model->ID_KOMENTAR ]);
},
],
[
'content' => $this->render('feedback_test'),
],
But I got this error:
PHP Warning – yii\base\ErrorException
call_user_func() expects parameter 1 to be a valid callback, function '
<div class="feedback-form">
<p>test</p>
</div>' not found or invalid function name
How do I include the active form in the grid view's column?
Try this.
[
'content' => function($model, $key, $index, $column) {
echo $this->render('feedback_test');
OR
echo $this->render('feedback_test', ['model' => $model]);
},
],
The above answer outputted the form above my grid. I wanted the form in one of my columns for every row of data. I ended up customizing an ActionColumn like this:
[
'class' => 'yii\grid\ActionColumn',
'template' => '{map}',
'contentOptions' => ['class' => 'text-center'],
'buttons' => [
'map' => function ($model) use ($m, $r) {
return $this->render('_form', ['model' => $m, 'req' => $model, 'ref' => $r]);
},
],
'urlCreator' => function ($action, $model) {
if ($action === 'map') {
return $model;
}
},
]
Related
MODEL
public function getJumlah()
{
return $this->hasMany(AssetMaster::className(), ['id_asset_received' => 'received_date'])
->leftJoin('asset_received','asset_received.id_asset_received = asset_master.id_asset_master')
->groupBy('received_date')
->count();
}
VIEW
<?= GridView::widget(
[
'behaviors' => [
[
'class' => '\dosamigos\grid\behaviors\GroupColumnsBehavior',
'extraRowColumns' => ['assetMaster.asset_name'],
'extraRowValue' => function($model, $key, $index, $totals) {
return '<span class="label label-warning">' . $model['received_year'] . '</span>';
},
'mergeColumns' => ['assetMaster.asset_name','received_year']
]
],
'columns' => [
'assetMaster.asset_name',
received_date',
'received_year',
'Jumlah'
],
'dataProvider' => $dataProvider,
'layout' => "\n{items}\n{pager}"
]
);
?> '
i want sum "nama barang " every search i use , for now "jumlah" is the result of COUNT
and make it into just one line, is there anyone who can help
view
Using the onclick Event in gridview?
error : Trying to get property of non-object
['class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete} {myButton}',
'buttons' => [
'format' => 'raw',
'myButton' => function ($model) {
return Html::a('<li class="fa fa-folder"></li> info sale', ['#'], [
'class' => 'btn btn-primary btn-xs',
'onclick'=>'saleinfo('.$model->id.')',
]);
}
]
],
You could try this way
['class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete} {myButton}',
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
....
}
if ($action === 'update') {
...
}
if ($action === 'myButton') {
$url =\yii\helpers\Url::to(['/your_controller/your_action', 'id' => $model->id]);
return $url;
}
},
'buttons' => [
'myButton' => function($url, $model){
return Html::a('<li class="fa fa-folder"></li> info sale', ['#'], [
'class' => 'btn btn-primary btn-xs',
]);
}
],
],
I have a listing page where I display email lists and if I want to delete any list I do not actually delete it but it is marked as deleted in the table column.
For the email_lists I am using the GridView widget for displaying the lists and I want to highlight a row if it is marked as deleted in the table email_lists.
Any idea how can I highlight the whole row instead of column?
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'name',
'total_recipients',
'list_type',
// 'is_deleted',
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Actions',
'template' => '{update}{view_list}{delete}',
'buttons' => [
'view_list' => function($url, $data, $key) {
return Html::a('<i class="glyphicon glyphicon-eye-open"></i>', ['/promos/promolistemails/index', 'id' => $data->id], ['title' => 'View List Emails']);
},
'update' => function($url, $data, $key) {
if ($data->list_type == 'custom') {
return Html::a('<i class="fa fa-pencil"></i>', '#.', ['title' => 'Edit List Emails', 'data-url' => yii\helpers\Url::to(['/promos/promolists/update', 'id' => $data->id]), 'class' => 'edit-list']);
}
},
'delete' => function($url, $data, $key) {
if ($data->list_type == 'custom') {
return Html::a('<i class="fa fa-trash"></i>', $url, ['title' => 'Delete List', 'data-method' => 'post', 'id' => 'delete-list']);
}
},
]
],
],
]); ?>
i need to use the rowOptions for the GridView
'rowOptions'=>function ($model, $key, $index, $grid){if($model->is_deleted){return ['class'=>'red'];}},
Try This one
'rowOptions' => function($model, $key, $index, $grid){
if($model->is_deleted){
return ['class' => 'danger'];
}
},
Am using kartik dynagrid and i would like to setup a text that shows when the dataprovider returns empty
The grid
echo DynaGrid::widget([
'columns' => $columns,
'showPersonalize' => true,
'emptyText'=>'Sorry all pr have pritems',///-----------------This is what i had set
'options' => ['id' => 'assignsolic-grid'],
'gridOptions' => [
'options' => ['id' => 'grid'],
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'showPageSummary'=>false,
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
'maxButtonCount' => 10,
],
'panel' => [
'type' => GridView::TYPE_PRIMARY,
// 'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i> </h3>',
'before'=>'<i>Select the Prs to assign solicitation and then click the Assign Solicitation button</i>',
'after' =>
Html::button(' <i class=" glyphicon glyphicon-road "></i> Assign Solicitation ', ['value' => Url::to('assignsolc'),'class' => 'btn btn-danger', 'id' => 'assignsolic']),
'footer' => false
],
'toolbar' => [
['content' => '{dynagridFilter}{dynagridSort}{dynagrid}'],
'{export}',
'{toggleData}'
],
'pjax' => true,
'bordered' => false,
'striped' => true,
'condensed' => true,
'responsive' => true,
'responsiveWrap' => false,
'containerOptions'=>['style'=>'overflow:scroll'],
]
]) ;
This returs an error of Setting unknown property: kartik\dynagrid\DynaGrid::emptyText how can i set the empty text
You can define the value for null display directly in confi/main.php formatter component
'components' => [
.......
'formatter' => [
'class' => 'yii\i18n\Formatter',
'dateFormat' => 'dd.MM.yyyy',
'decimalSeparator' => ',',
'thousandSeparator' => ' ',
'currencyCode' => 'EUR',
'nullDisplay' => '', // **** this param
],
.....
Otherwise if the widget don't provide a proper attribute you can use an anonymous function for value
[
'attribute' => 'your_attribute',
'value' => function ($model) {
if ( $model->your_attribute == NULL) {
return 'Sorry all pr have pritems';
} else {
return $model->your_attribute;
}
},
],
Since am using $dataProvider i found out that i just have to check if the dataProvider is empty by
if (!$dataProvider->totalCount > 0) { pass in message to display }
else{?>
SHOW THE GRID HERE
<?php
}
?>
?>
Fighting form last 3 days not able to find what exactly problem is. When after search I export data it export all data, expected to export search result.Please help!
My Controller
public function actionAdvancesearch()
{
$searchModel = new CandidateSearch();
$model = new Candidate();
$dataProvider1 = $searchModel->search(Yii::$app->request->queryParams);
if(Yii::$app->request->post()){
$postedData=Yii::$app->request->post();
$searchModel = new CandidateSearch();
$dataProvider1 = $searchModel->searchAdvanced();
return $this->render('candidateAdvSearch', ['dataProvider1' => $dataProvider1,
'model' => $model ,
'searchModel' => $searchModel,
'posted'=>"posted",
'postedData'=>$postedData]);
}else{
return $this->render('candidateAdvSearch', ['searchModel' => $searchModel, 'model' => $model, 'dataProvider1' => $dataProvider1]);
}
}
View
Pjax::begin();
if($dataProvider1){
$gridColumns = [
[
'attribute'=>'HRMS_candidateID',
'label'=>'Candidate ID',
'vAlign'=>'middle',
'width'=>'190px',
'value'=>function ($model, $key, $index, $widget) {
return $model->HRMS_candidateID;
},
'format'=>'raw'
],
[
'attribute'=>'HRMS_candidateFirstName',
'label'=>'Candidate FirstName',
'vAlign'=>'middle',
'width'=>'190px',
'value'=>function ($model, $key, $index, $widget) {
return $model->HRMS_candidateFirstName;
},
'format'=>'raw'
],
[
'attribute'=>'HRMS_candidateLastName',
'label'=>'Candidate LastName',
'vAlign'=>'middle',
'width'=>'190px',
'value'=>function ($model, $key, $index, $widget) {
return $model->HRMS_candidateLastName; },
'format'=>'raw'
],
];
$fullExportMenu = ExportMenu::widget([
'dataProvider' => $dataProvider1,
'columns' => $gridColumns,
'target' => ExportMenu::TARGET_POPUP,
'fontAwesome' => true,
'pjaxContainerId' => 'kv-pjax-container',
'dropdownOptions' => [
'label' => 'Full',
'class' => 'btn btn-default',
'itemsBefore' => [
'<li class="dropdown-header">Export All Data</li>',
],
],
]);
// Generate a bootstrap responsive striped table with row highlighted on hover
echo GridView::widget([
'dataProvider' => $dataProvider1,
'columns' => $gridColumns,
'pjax' => true,
'pjaxSettings' => ['options' => ['id' => 'kv-pjax-container']],
'panel' => [
'type' => GridView::TYPE_PRIMARY,
'heading' => '<h3 class="panel-title"><i class="glyphicon glyphicon-book"></i> Candidate Advanced Search</h3>',
],
'toolbar' => [
$fullExportMenu,
],
'striped'=>true,
'hover'=>true,
'responsive'=>true,
'hover'=>true,
'resizableColumns'=>true,
'persistResize'=>false,
'columns' => $gridColumns,
]);
}
Pjax::end();