Retrieving data from Gridview as array in Yii2 - yii2

i'd like to ask how to retrieving data as array from gridview
as mentioned in this thread
How can I get the selected data/item rows in CheckboxColumn Gridview - Yii2
what i have been doing is :
in the controller
public function actionCetakdispo{
$action=Yii::$app->request->post('action');
$selection=(array)Yii::$app->request->post('selection');
print_r($selection);
exit;
}
in view :
<?=Html::beginForm(['controller/rekapsm'],'post');?>
<?= Html::a('Cetak Dispo', ['cetakdispo'], ['class' => 'btn btn-
primary']) ?>
<?= Html::a('Cetak Register', ['cetakreg'], ['class' => 'btn btn-
primary']) ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'kategori',
'nama_wp',
'nama',
'nomor_surat',
'tgl_surat',
'perihal',
'ket',
['class' => 'yii\grid\CheckboxColumn'],
],
]); ?>
but nothing data retrieve to array..please give me lessons or referrence to read..many thanks..
UPDATED :
i change view become likethis :
<div class="row" style="margin-left:870px;" >
<?=Html::beginForm(['cetakdispo'],'post');?>
<?=Html::submitButton('Cetak Dispo', ['class' => 'btn btn-primary']);?>
<?= Html::a('Cetak Register', ['cetakreg'], ['class' => 'btn btn-primary']) ?>
</div>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn',],
'id',
'kategori',
'nama_wp',
'nama',
'nomor_surat',
'tgl_surat',
'perihal',
'ket',
['class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => function($model, $key, $index, $widget) {
return ['value' => $model['id'] ];
},],
],
]); ?>
<?= Html::endForm();?>
</div>
and its works...

Related

PJax() not working in yii2

I have two modules. The one won't create traffic using Pjax(). This one with exact same code for Grid will create traffic. Any ideas, why?
Here is exactly same Gridcode for both modules:
<?=
Html::endForm();
Pjax::begin();//this is ineffective! Why !!
?>
<div class="col-md-10">
<div class="box box-primary">
<?=
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'filterSelector' => '.choiceRadio',
'id' => 'cb',
'columns' => $gridColumn,
'options' => [
'style' => 'overflow: auto; word-wrap: break-word;'
],
'pjax' => true,
'pjaxSettings' => [
'neverTimeout' => true,
],
'panel' => [
"heading" => "<h3 class='panel-title'><i class='glyphicon glyphicon-globe'></i> " . $this->title . "</h3>",
'type' => 'danger',
'after' => Html::a('<i class="glyphicon glyphicon-repeat"></i> Reset Grid', ['/mail/mail-eingang/index'], ['class' => 'btn btn-warning', 'title' => 'Setzt die GridView zurück']),
'toggleDataOptions' => ['minCount' => 10],
],
'toolbar' => [
'{export}',
'{toggleData}'
],
]);
Pjax::end();
?>
</div>
</div>
</div>

Yii2 - Kartik - Export - Exporting file isn't actually performed, although it shows it does

I'm trying to use yii2-export extention.
When I export, after pressing OK for the 'disable any popup...' message, the pop up window appears, but no download is being done.
My code:
use kartik\export\ExportMenu;
$gridColumns = [
['class' => 'yii\grid\SerialColumn'],
'idCandidate',
['class' => 'yii\grid\ActionColumn'],
];
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns
]);
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'exportConfig' => [
GridView::HTML => [],
GridView::CSV => [],
]
]);
Any idea?
Thanks.

How to add a new column to the gridview in yii2?

I have 4 columns in my GridView, which contains the data I need, but now I need one more column. How can I create it in my GridView?
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'surname',
'employment_date',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Thanks for the help
you can add more columns according to yii api:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'surname',
'employment_date',
[
'class' => DataColumn::className(), // this line is optional
'attribute' => 'name',
'format' => 'text',
'label' => 'Name',
],
['class' => CheckboxColumn::className()],
['class' => 'yii\grid\ActionColumn'],
]
]); ?>
you can read this link
<?= GridView::widget([
....
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'surname',
'employment_date',
'columns'=>[
'attribute'=>'New Column',
'value'=>'tbl.new_column'
],
//OR This
new_column,
['class' => 'yii\grid\ActionColumn'],
],
]); ?>

How to remove summary in yii2 grid but keeping pager

I'm using following code which is generated by the Gii tool while creting CRUD operation
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'text:ntext',
'status',
'name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?>
You can use layout :
<?= GridView::widget([
'dataProvider' => $dataProvider,
'layout' => "{items}\n{pager}",
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'text:ntext',
'status',
'name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Add "summary" key and pass it blank.
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'summary'=>'',
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'text:ntext',
'status',
'name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?>

Undefined variable: gridColumns in karik gridview:yii2

I'm trying to use kartik gridview and got the following error. -
Undefined variable: gridColumns
I've checked - Yii2: Kartik Gridview sum of a column in footer. But didn't find the issue in my code.
Code of index.php -
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => $gridColumns,
'showPageSummary' => true,
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
[
'attribute'=>'s_period',
'filter'=>ArrayHelper::map(Salary::find()->asArray()->all(), 's_period', 's_period'),
],
's_empid',
's_empname',
[
'attribute'=>'s_epf',
'pageSummary'=>true
],
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
if you assign manually the columns you don't need a var iwth columns specification so remove it
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//'columns' => $gridColumns,
'showPageSummary' => true,
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
[
'attribute'=>'s_period',
'filter'=>ArrayHelper::map(Salary::find()->asArray()->all(), 's_period', 's_period'),
],
's_empid',
's_empname',
[
'attribute'=>'s_epf',
'pageSummary'=>true
],
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>