0

I'm developing a custom extension for my client. There are two tables which hold the complete data.

primary_table

id_primary | name | age | image
===========|======|=====|===================
    1      | Kush | 18  | a/c/aclong.jpg
    2      | Lav  | 19  | b/o/bottle.png

and

secondary_table

id_seconday | id_primary | item_name | quantity
============|============|===========|=========
    1       |   1        |  pen      |   4
    2       |   1        |  pencil   |   2
    3       |   2        |  eraser   |   1
    4       |   2        | sharpner  |   1
    5       |   2        |  ruler    |   2

I am able to show custom form to user and save the data. But while showing the data in the admin, I have a problem. As the normal Grid in the admin is simply a 2-D table, how can I display the details all at once?

One approach I think is to display the secondary_table data as a table in one of the columns of the Grid. But how I can achieve that? How to make a table in a column of the grid? Or how to display this data simply?

Sample Display that I want.

Primary ID | Name | Age | Image |           Secondary Data
===========|======|=====|=======|=======================================
           |      |     |       |  Item Name | Quantity
    1      | Kush | 18  | ****  | -----------|---------   
           |      |     |       |    Pen     |    4
           |      |     |       |    Pencil  |    2
-----------|------|-----|-------|---------------------------------------
           |      |     |       |  Item Name | Quantity
     2     | Lav  | 19  | ****  | -----------|----------
           |      |     |       |    Eraser  |    1
           |      |     |       |   Sharpner |    1
           |      |     |       |    Ruler   |    2

I have a working code to display everything except the last Secondary Data column. The code is same as the one created with moduleCreator. Please help me with that last column. Thank you.

1 Answer 1

0

From what I see here you need a table inside a column.
You could make a method that returns the value for secondary data as a html table.

So if you have the column definition like this:

   $this->addColumn('column_id', array(
        'header'    => $this->__('Column label'),
        'index'     => 'column_code',
    )); 

you need to add a getter membmer

    $this->addColumn('column_id', array(
        'header'    => $this->__('Column label'),
        'index'     => 'column_code',
        'getter'    => 'getFormatedValues'
    )); 

Now on your main model you need to implement the getFormatedValues method that will return the data you need, wrapped in a table:

public function getFormatedValues() {
    return '<table><tr><td>....YOUR DATA HERE</td></tr></table>';
}
2
  • Thank you. I was already trying this. I'm stuck at how to run the query prepared using following statements. $collection = Mage::getModel('prescription/prescriptiondata')->getCollection(); $collection->getSelect()->where("main_table.id = $value"); and then how to retrieve the data to display in the table.
    – kushpf
    Commented Oct 6, 2014 at 14:27
  • $collection->getData(); is what I wanted. Thank you.
    – kushpf
    Commented Oct 6, 2014 at 14:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.