logo
down
shadow

How to use one big query instead of one by one queries in Yii2 Kartik GridView?


How to use one big query instead of one by one queries in Yii2 Kartik GridView?

By : Gilberth
Date : November 22 2020, 10:31 AM
it fixes the issue Take a look at eager loading vs lazy loading, like deacs told you. This is the official link: http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#lazy-and-eager-loading
With datatables you will not solve the issue, you still have to load all the data and only eager loading will solve it. You should see a huge improvement in your view. Also use the debug toolbar to make sure you implement it properly and to watch the number of queries plummet.
code :


Share : facebook icon twitter icon
Yii2: Kartik Gridview sum of a column in footer

Yii2: Kartik Gridview sum of a column in footer


By : patinok
Date : March 29 2020, 07:55 AM
Disable pagination in kartik-v/yii2-grid Kartik Gridview

Disable pagination in kartik-v/yii2-grid Kartik Gridview


By : derf
Date : March 29 2020, 07:55 AM
wish help you to fix your issue No pagination mean show all the instance then you can set pageSize = 0
code :
       $dataProvider->pagination->pageSize=0;
       $dataProvider->pagination  = false;
Yii2 Kartik GridView Word-Wrapping

Yii2 Kartik GridView Word-Wrapping


By : Murilo Carvalho de S
Date : March 29 2020, 07:55 AM
should help you out Has anyone been able to set up word-wrapping for a Yii GridView DataColumn?
code :
Try using options

 'options' => [
    'style'=>'max-width:150px; min-height:100px; overflow: auto; word-wrap: break-word;'
],
[
 'class' => 'kartik\grid\DataColumn',
  'attribute'=>'',
  'format'=>'raw',   
  'value' => function($model) {
     return 'span  'style'='max-width:150px; min-height:100px; 
               overflow: auto; word-wrap: break-word;' . $model->description  
            .  </span> 
      },
   ],
],
Kartik's yii2-grid: Setting unknown property: kartik\grid\GridView::panel

Kartik's yii2-grid: Setting unknown property: kartik\grid\GridView::panel


By : DDPSP
Date : March 29 2020, 07:55 AM
wish of those help For the life of me, I'm unable to sort the following error out when using Kartik's yii2-grid: , seems you have a blank in the attribute 'panel '
code :
 'panel ' => [
        'heading'=>'<h1>'.Html::encode(mb_strtoupper($this->title)).'</h1>', 
    ],
   'panel' => [
        'heading'=>'<h1>'.Html::encode(mb_strtoupper($this->title)).'</h1>', 
    ],
Calculate average from kartik gridview(YII2)

Calculate average from kartik gridview(YII2)


By : J. Maidana
Date : March 29 2020, 07:55 AM
Any of those help This was the already answered question and was correct answer, but I think you are not able to figure-out the solution.
Now add this code on your view page and try
code :
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use kartik\grid\GridView;
use yii\data\ActiveDataProvider;
use backend\models\Penerimaan;
use yii\web\App;
/* @var $this yii\web\View */
/* @var $model backend\models\Triwulan */

$this->title = $model->rm_code;
$this->params['breadcrumbs'][] = ['label' => 'Triwulan', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="triwulan-view">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('Update', ['update', 'id' => $model->rm_code], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('Delete', ['delete', 'id' => $model->rm_code], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'rm_code',
            'deskripsi_barang',
        ],
    ]) ?>
 <?php
    $myAverage = 0;
    $myTot  =0;
    $myCnt = 0;
    $data = $dataProvider->getModels();

    foreach ($data as $key => $value) {
        $myTot += $value['price'];
        $myCnt++;
    }
    if ($myCnt>0){  
      $myAverage = $myTot/$myCnt;
    }
   echo $myAverage;  // your average displayed herre, you can place it wherever you want.
      ?>

       <?= GridView::widget([
              'dataProvider'=>new yii\data\ActiveDataProvider([

                 'pagination'=>false,
                 'query'=>$model->getPenerimaans(),

              ]),
              'columns'=>[
                ['class' => 'kartik\grid\SerialColumn'],


                 [
                   'attribute'=>'bulan',
                       'pageSummary' => 'Jumlah',
                ],                     
               [
                'attribute' => 'price' ,
                'pageSummary' =>(true),
                'value' => function ($model) {
                        if($model)
                         return  $model->price;
                        }
               ],

            ],
              'showPageSummary' => true,
         ])
      ?> 
   </div>
</div>
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org