PJax() not working in yii2 - 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>

Related

Retrieving data from Gridview as array in 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...

Specify Font Size of Gridview in yii2

I'm printing gridview in pdf. The gridview is fine. But the cells are not filling in properly. I think if I can decrease the font a bit, the cell will be filled in properly. I've decreased the width. But the cells are being distorted.
Code of Gridview -
<?= GridView::widget([
'dataProvider' => $dataProvider1,
//'filterModel' => $searchModel,
'layout'=>"{items}",
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'hsncode',
[
'label' => 'Productname',
'attribute' =>'productname',
'headerOptions' => ['style' => 'width:20%'],
//'contentOptions' => ['class' => 'col-lg-1'],
//'format'=>['decimal',2]
],
'batchno',
//'expdate',
[
'attribute'=>'expdate',
'format'=>['DateTime','php:m-y'],
'headerOptions' => ['style' => 'width:6%'],
],
'mrp',
'rate',
'qty',
'free',
'discount',
[
'label' => 'Value',
'attribute' =>'value',
//'contentOptions' => ['class' => 'col-lg-1'],
'format'=>['decimal',2]
],
[
'label' => 'GST%',
'attribute' =>'gstpercent',
//'headerOptions' => ['style' => 'width:6%'],
//'contentOptions' => ['class' => 'col-lg-1'],
'format'=>['decimal',0]
],
[
'label' => 'Total',
'attribute' =>'totalamount',
'headerOptions' => ['style' => 'width:9%'],
//'contentOptions' => ['class' => 'col-lg-1'],
'format'=>['decimal',2]
],
],
]); ?>
Gridview looks like -
Please let me know how to specify the font in gridview.
you could use options for the grid container
<?= GridView::widget([
'dataProvider' => $dataProvider1,
//'filterModel' => $searchModel,
'layout'=>"{items}",
'options' => ['style' => 'font-size:12px;']
'columns' => [
or directly in column
<?= GridView::widget([
'dataProvider' => $dataProvider1,
//'filterModel' => $searchModel,
'layout'=>"{items}",
'options' => ['style' => 'font-size:12px;']
'columns' => [
[
'label' => 'your_label',
'attribute' =>'your_attribute',
'contentOptions' => ['style' => 'font-size:12px;']
]

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'],
],
]); ?>

Page Layout in Yii2

Contents are going under the top Navigation bar. Sometimes it shows right. Sometimes the problem occurs. Please help. Attaching picture of the error page.I am giving my views/layout/main file below. The content of the page is a bit in upward direction.
<?php
/* #var $this \yii\web\View */
/* #var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;
use kartik\sidenav\SideNav;
use yii\helpers\Url;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'GM Pharmaceuticals',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<div class="container-fluid">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<div class="col-xs-4 col-sm-4 col-lg-2" style="padding-left: 0px;">
<?php
echo SideNav::widget([
'type' => SideNav::TYPE_DEFAULT,
'heading' => '<i class="glyphicon glyphicon-cog"></i> Menu',
'items' => [
[
'url' => Yii::$app->homeUrl,
'label' => 'Home',
'icon' => 'home',
],
[
'label' => 'Product',
'icon' => 'glyphicon glyphicon-baby-formula',
//'visible'=>Yii::$app->user->can('s_add-parties'),
'items' => [
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=batchno/productbatch/create',
'label' => 'New Batch',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('c_billing-person'),
],
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=batchno/productbatch',
'label' => 'Edit Batch',
'icon' => 'glyphicon glyphicon-edit',
'visible'=>Yii::$app->user->can('c_billing-person'),
],
],
],
[
'label' => 'Party',
'icon' => 'glyphicon glyphicon-user',
//'visible'=>Yii::$app->user->can('s_add-parties'),
'items' => [
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=Parties/parties',
'label' => 'New Party',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('s_add-parties'),
],
],
],
[
'url' => 'http://localhost:8080/advanced/backend/web/index.php?r=tc/bills',
'label' => 'Transport',
'icon' => 'glyphicon glyphicon-send',
'visible'=>Yii::$app->user->can('c_billing-person'),
],
[
'label' => 'Payment',
'icon' => 'glyphicon glyphicon-piggy-bank',
'visible'=>Yii::$app->user->can('c_payment-collection'),
'items' => [
[
//'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=payment/payment',
'label' => 'Gopalbabu',
'icon' => 'glyphicon glyphicon-usd',
'visible'=>Yii::$app->user->can('s_create-payment'),
'items' =>[
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=payment/payment/create',
'label' => 'New',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=payment/payment',
'label' => 'View & Update',
'icon' => 'glyphicon glyphicon-edit',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
],
],
[
//'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=sbp/payments',
'label' => 'Sanatbabu',
'icon' => 'glyphicon glyphicon-usd',
'visible'=>Yii::$app->user->can('s_create-payment'),
'items' =>[
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=sbp%2Fpayments%2Fcreate',
'label' => 'New',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=sbp/payments',
'label' => 'View & Update',
'icon' => 'glyphicon glyphicon-edit',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
],
],
],
],
[
'label' => 'Help',
'icon' => 'question-sign',
'items' => [
['label' => 'About', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Contact', 'icon'=>'phone', 'url'=>'#'],
],
],
],
]);
?>
</div>
<div class="col-xs-8 col-sm-8 col-lg-10" style="padding-left: 0px;">
<?= $content ?>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">© My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
I guess you have missed a <div>,
try <br> tag after main div in views/layout/main.php
or check one by one all divs starting and closing properly.
I found the solution. I changed <div class="container-fluid"> to <div class="container"> and it worked.

yii2 ExportMenu results empty page if columns > 10

I'm using kartik\export\ExportMenu to provide csv exports.
If I want to export approx. more that 10 columns it results just a empty page with no error. Also the yii error log has no entry. With less columns it works.
I tried the following settings but none of them solved it:
'batchSize' => .. tried from 100 to 1000
'streamAfterSave' => false
In case of streaming after file creation it creates any empty file (0B).
Any ideas? Thanks.
--- snip ---
<?php
$fullExportMenu = ExportMenu::widget([
'dataProvider' => $dataProvider,
'columns' => $gridColumns,
'emptyText' => 'Keine Daten verfügbar.',
'fontAwesome' => true,
'filename' => 'Webshop_Produkte',
'showColumnSelector' => false,
//'noExportColumns' => [0,1]
//'pjaxContainerId' => 'kv-pjax-container',
'dropdownOptions' => [
'label' => 'Alle Daten',
'class' => 'btn btn-default'
],
'batchSize' => 500,
//'target' => ExportMenu::TARGET_POPUP,
'stream' => false,
'streamAfterSave' => false,
'afterSaveView' => '#app/views/webshop-product/download',
'folder' => '#app/web/downloads',
//'linkPath' => '/downloads',
//'exportConfig' => $exportConfig,
]);
echo $fullExportMenu . ' ' .
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'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> Datei Export</h3>',
],
// set a label for default menu
'export' => [
'label' => 'Aktuelle Seite',
'fontAwesome' => true,
],
// your toolbar can include the additional full export menu
'toolbar' => [
'{export}',
// $fullExportMenu,
['content' =>
Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], [
'data-pjax' => 0,
'class' => 'btn btn-default',
'title' => Yii::t('kvgrid', 'Reset Grid')
])
. ' ' .
Html::submitButton('Tabelle leeren', ['name' => 'truncate', 'class' => 'btn btn-danger',
'data-confirm' => 'Wollen Sie wirklich die Tabelle leeren?'
. 'Achtung: Löschen kann nicht rückgänig gemacht werden.'
])
. ' ' .
Html::submitButton('Alles', ['name' => 'download', 'class' => 'btn btn-danger',
'data-confirm' => 'Wollen Sie wirklich alles exportieren?'
])
],
]
]);
?>
--- snap ---