1

I have an array of data very similar to this

$array = [
  'FUNDSCTR' => '10000001' 
  'RCMMTITEM' => 'R400001'
  'YEAR' => '2018'
  'CONSUMA' => 5898257
  'CONSUME' => 30140
  'AVAIL' => 5868117 ]

and use in ArrayDataProvider

 $dataProvider = new ArrayDataProvider(['allModels' => $array,]);

code in gridview

 <?= GridView::widget([
         'dataProvider' => $dataProvider,
         'columns' => [
                      ['class' => 'kartik\grid\SerialColumn'],
                        [
                            'label' => 'Year',
                            'attribute'=>'YEAR',
                        ],
                        [
                            'label' => 'Fund',
                            'attribute'=>'FUNDSCTR',
                        ],
                         [
                            'label' => 'Item',
                            'attribute'=>'RCMMTITEM',
                        ],
                         [
                            'label' => 'Consumeable',
                            'attribute'=>'CONSUMA',
                        ],
                         [
                            'label' => 'Consumed',
                            'attribute'=>'CONSUME',
                        ],
                        [
                            'attribute'=>'Available',
                            'value'=> 'AVAIL',
                        ],
                    ]);
                ?>
      </div>

resluts enter image description here

print_r($dataProvider); ~ $arrays return

yii\data\ArrayDataProvider Object ( [key] => [allModels] => Array ( [RFUNDSCTR] => 10000001 [RCMMTITEM] => R400013 [RYEAR] => 2018 [CONSUMA] => 5898257 [CONSUME] => 30140 [AVAIL] => 5868117 )

I need to show in gridView data like this.

enter image description here

1 Answer 1

2

To work properly, an array which you pass to ArrayDataProvider should be two-dimensional, like this:

$array = [
    [
        'FUNDSCTR' => '10000001',
        'RCMMTITEM' => 'R400001',
        'YEAR' => '2018',
        'CONSUMA' => 5898257,
        'CONSUME' => 30140,
        'AVAIL' => 5868117,
    ],
    [
        'FUNDSCTR' => '10000001',
        'RCMMTITEM' => 'R400001',
        'YEAR' => '2018',
        'CONSUMA' => 5898257,
        'CONSUME' => 30140,
        'AVAIL' => 5868117,
    ],
    [
        'FUNDSCTR' => '10000001',
        'RCMMTITEM' => 'R400001',
        'YEAR' => '2018',
        'CONSUMA' => 5898257,
        'CONSUME' => 30140,
        'AVAIL' => 5868117,
    ]
];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.