Using an array as a data source for a CGridView

Im hoping this will work. Im an application for writing and billing and you want to save the current account in an array that can be placed in the blob field. It will also be used for archive changes, etc.

Invoice sales items are displayed using CGridView. The only thing in the documentation says that the data source is IDataProvider. I do not want to store the whole object in my Db, but something similar to this:

invoice->array( InvoiceHeader->array(//header information), InvoiceItems->array( item_1->array( item_id-> '1', item_count->'3', .... ), ), ), 

I would like to do this in my opinion:

 $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$this->invoiceItems, )); 

- side note. Persistent storage is a series of tables, this will be used to store active entries with browser errors, etc. The current system does this directly in the tables, but leads to non-competitive account numbers and inaccurate statistics.

+7
source share
2 answers

you can first transfer your array to CArrayDataProvider and then use it in CGridView -

 $invoiceItemsDataProvider = new CArrayDataProvider($this->invoiceItems); $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$invoiceItemsDataProvider, )); 
+14
source

This is an extension of my problem and solution. Mukesh's answer is 100% correct. but I needed to add buttons to the grid, but when I tried to add a delete button, I got an error. You need to adjust the URL in the button array as follows:

  array( // delete button 'class'=>'CButtonColumn', 'template'=>'{delete}', 'buttons'=>array( 'delete'=>array( 'url'=>'Yii::app()->controller->createUrl(\'Invoicing/invoiceBody/test\', array(\'id\'=>$data["id"]))', ), ), ), 

note that the identifier is declared using:

 array('id', $data['id']) 

not

 array('id', $data->id) 
+4
source

All Articles