1

I have create one custom tab in my module and display one grid output successfully, but my question is how we can display two grid serializer block in one page? I have tried to out put with calling two serializer block with this code.

public function customgridAction()

{
   $this->loadLayout();
    $this->getLayout()->getBlock('regionpage.productgrid')->setProductsGrid($this->getRequest()->getPost('products_grid', null));
    $this->getLayout()->getBlock('regionpage.articlegrid')->setArticlesGrid($this->getRequest()->getPost('articles_grid', null));
    $this->renderLayout();
}

And this is what my layout xml look like

<regionpage_adminhtml_regionpage_customgrid>
<block type="core/text_list" name="root">
    <block type="regionpage/adminhtml_regionpage_edit_tab_productgrid" name="regionpage.productgrid"/>
    <block type="adminhtml/widget_grid_serializer" name="regionpage_productgrid">
        <reference name="regionpage_productgrid">
            <action method="initSerializerBlock">
                <grid_block_name>regionpage.productgrid</grid_block_name>
                <data_callback>getSelectedProducts</data_callback>
                <hidden_input_name>links[productgrid]</hidden_input_name>
                <reload_param_name>products_grid</reload_param_name>
            </action>
            <action method="addColumnInputName">
                <input_name>position</input_name>
            </action>
        </reference>
    </block>
</block>

 <regionpage_adminhtml_regionpage_customgrid>
    <block type="core/text_list" name="root">
        <block type="regionpage/adminhtml_regionpage_edit_tab_articlegrid" name="regionpage.articlegrid"/>
        <block type="adminhtml/widget_grid_serializer" name="regionpage_articlegrid">
            <reference name="regionpage_articlegrid">
                <action method="initSerializerBlock">
                    <grid_block_name>regionpage.articlegrid</grid_block_name>
                    <data_callback>getSelectedArticles</data_callback>
                    <hidden_input_name>links[articlegrid]</hidden_input_name>
                    <reload_param_name>articles_grid</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </block>
 </regionpage_adminhtml_regionpage_customgrid>

But it output last block not both block.

I had asked this question on stackoverflow sometimes ago but not getting any answer so i thought to reposted it here

I have seen this meta question Can I repost unanswered questions from Stack Overflow? So I have reposted this question again here.

Stackoverflow question link https://stackoverflow.com/questions/13972662/grid-layout-in-magento

8
  • This is a good article on how grid's work, from what I can tell, I don't see any reason why you can't have two grids, what does your layout.xml look like? magentogarden.com/blog/… May 2 '13 at 14:25
  • i have refer this link magebase.com/magento-tutorials/… and how magento display upsell, cross sell product grid
    – Mufaddal
    May 3 '13 at 4:32
  • What does your layout look like?
    – davidalger
    May 9 '13 at 13:47
  • @davidalger I had added my layout
    – Mufaddal
    May 14 '13 at 10:04
  • what happens if you wrap the getBlocks in your controller with $this->_addContent($this->getLayout()->getBlock(''), 'block_name'); May 14 '13 at 18:07
2

Ok I think I have cracked it.

The problem appears to be when you are using the wrapping block

<block type="core/text_list" name="root">

Once you have defined a block of name "root" then it will be overridden if another block with the same name comes along later. (Correct me if I am wrong)

There are two solutions you could try.

  1. Combine both your xml into one section

Which would make your xml as follows

<regionpage_adminhtml_regionpage_customgrid>
    <block type="core/text_list" name="root">
    <block type="regionpage/adminhtml_regionpage_edit_tab_productgrid" name="regionpage.productgrid"/>
    <block type="adminhtml/widget_grid_serializer" name="regionpage_productgrid">
        <reference name="regionpage_productgrid">
            <action method="initSerializerBlock">
                <grid_block_name>regionpage.productgrid</grid_block_name>
                <data_callback>getSelectedProducts</data_callback>
                <hidden_input_name>links[productgrid]</hidden_input_name>
                <reload_param_name>products_grid</reload_param_name>
            </action>
            <action method="addColumnInputName">
                <input_name>position</input_name>
            </action>
        </reference>
    </block>
    <block type="regionpage/adminhtml_regionpage_edit_tab_articlegrid" name="regionpage.articlegrid"/>
        <block type="adminhtml/widget_grid_serializer" name="regionpage_articlegrid">
            <reference name="regionpage_articlegrid">
                <action method="initSerializerBlock">
                    <grid_block_name>regionpage.articlegrid</grid_block_name>
                    <data_callback>getSelectedArticles</data_callback>
                    <hidden_input_name>links[articlegrid]</hidden_input_name>
                    <reload_param_name>articles_grid</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </block>
</regionpage_adminhtml_regionpage_customgrid>
  1. Simple replace in your second section the follow section

With a reference node which would make your second section look like

<regionpage_adminhtml_regionpage_customgrid>
    <reference name="root">
    <block type="regionpage/adminhtml_regionpage_edit_tab_articlegrid" name="regionpage.articlegrid"/>
        <block type="adminhtml/widget_grid_serializer" name="regionpage_articlegrid">
            <reference name="regionpage_articlegrid">
                <action method="initSerializerBlock">
                    <grid_block_name>regionpage.articlegrid</grid_block_name>
                    <data_callback>getSelectedArticles</data_callback>
                    <hidden_input_name>links[articlegrid]</hidden_input_name>
                    <reload_param_name>articles_grid</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </reference>
</regionpage_adminhtml_regionpage_customgrid>

Hope this fixes it and is a good enough explanation :)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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