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(); ?>
Related
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...
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>
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'],
],
]); ?>
i am trying to use kartik export and its not working for me. In config file I have added following code:
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
],
],
In Composer i have added folowing code
"kartik-v/yii2-export": "#dev",
"kartik-v/yii2-mpdf":"#dev",
"kartik-v/yii2-grid": "#dev"
My view code is like this:
<?php
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\bootstrap\Tabs;
use kartik\export\ExportMenu;
use yii\widgets\Pjax;
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="general-info-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php
<p>
<?= Html::a('create', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php
$gridColumns = [
'sfcl_name',
[
'attribute'=> 'org_type',
'value' => 'orgType.cv_lbl'
],
];
echo ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns
]);
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax'=>true,
'columns' => [
'sfcl_name',
'phone',
[
'attribute'=>'regd_dt_ad',
'format'=>['date', 'php:Y-M-d'],
'xlFormat'=>'mmm\-dd\, yyyy', // different date format
'width'=>'100px'
],
[
'attribute'=> 'org_type',
'value' => 'orgType.cv_lbl'
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>
My controller code is:
My controller code to call this view : public function actionIndex()
{
$searchModel = new SfclGeneralSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
On click of export menu nothing is happening.In tutorial i saw there were options for exporting to pdf ,html,csv,json,text.such options doesnot appers in my case.Is the css not working or what?
you run "composer update" command?.
also in your web.php
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
],
],
add the property downloadAction, like this:
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module',
'downloadAction' => 'gridview/export/download',
]
],
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'],
],
]); ?>