0

I have a custom grid, when I click on arrow(as under lined), for next or previous records, two grids papers on screen as shown in pic . I have followed Link1 and Link2 not helping me.Don't know where I am doing wrong. And my controller actions are

<?php

class Abc_Xyz_Adminhtml_TypesController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->_title($this->__('Xyz'))->_title($this->__('Types'));
        $this->loadLayout();
        $this->_setActiveMenu('abc_xyz/types');
        $this->_addContent($this->getLayout()->createBlock('abc_xyz/adminhtml_types'));
        $this->renderLayout();
    }

    public function gridAction() {
    $this->loadLayout();
    $this->getResponse()->setBody(
            $this->getLayout()->createBlock('abc_xyz/adminhtml_types_grid')->toHtml()
    );
}

public function editAction() {
    $id     = $this->getRequest()->getParam('id');
    $model  = Mage::getModel('abc_xyz/types')->load($id);

    if ($model->getId() || $id == 0) {
        $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
        if (!empty($data)) {
            $model->setData($data);
        }

        Mage::register('xyz_data', $model);

        $this->loadLayout();
        $this->_setActiveMenu('abc_xyz/types');

        $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Xyz'), Mage::helper('adminhtml')->__('Xyz'));
        $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Types'), Mage::helper('adminhtml')->__('Types'));

        $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

        $this->_addContent($this->getLayout()->createBlock('abc_xyz/adminhtml_types_edit'))
            ->_addLeft($this->getLayout()->createBlock('abc_xyz/adminhtml_types_edit_tabs'));

        $this->renderLayout();
    } else {
        Mage::getSingleton('adminhtml/session')->addError(Mage::helper('abc_xyz')->__('Type does not exist.'));
        $this->_redirect('*/*/');
    }
}

public function newAction() {
    $this->_forward('edit');
}

public function saveAction() {
    if ($data = $this->getRequest()->getPost()) {
        $entityId = $this->getRequest()->getPost('entity_id');
        $model = Mage::getModel('abc_xyz/types');

        if (!empty($entityId)) {
            $model->load($entityId);    
        } else {
            unset($data['entity_id']);
        }

        $model->setData($data);

        try {
            $model->save();
            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('abc_xyz')->__('Type Successfully Saved.'));
            Mage::getSingleton('adminhtml/session')->setFormData(false);

            if ($this->getRequest()->getParam('back')) {
                $this->_redirect('*/*/edit', array('id' => $model->getId()));
                return;
            }
            $this->_redirect('*/*/');
            return;
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            Mage::getSingleton('adminhtml/session')->setFormData($data);
            $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            return;
        }
    }
    Mage::getSingleton('adminhtml/session')->addError(Mage::helper('abc_xyz')->__('Unable to load type.'));
    $this->_redirect('*/*/');
}

public function deleteAction() {
    if ($data = $this->getRequest()->getParams()) {
        $entityId = $this->getRequest()->getParam('id');
        try {
            $model = Mage::getModel('abc_xyz/types');

            $model->setId($entityId)->delete();

            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Type was successfully deleted.'));

            $this->_redirect('*/*/');

        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
        }
    }
    $this->_redirect('*/*/');
}

}

config.xml

    <?xml version="1.0"?>
<config>
    <modules>
        <Abc_Xyz>
            <version>1.4.0</version>
        </Abc_Xyz>
    </modules>
    <global>
        <models>
            <abc_xyz>
                <class>Abc_Xyz_Model</class>
                <resourceModel>abc_xyz_resource</resourceModel>
            </abc_xyz>
            <abc_xyz_resource>
                <class>Abc_Xyz_Model_Resource</class>
                <entities>
                    <associations>
                        <table>xyz_associations</table>
                    </associations>
                    <types>
                        <table>xyz_types</table>
                    </types>
                </entities>
            </abc_xyz_resource>
        </models>
        <blocks>
            <abc_xyz>
                <class>Abc_Xyz_Block</class>
            </abc_xyz>
            <adminhtml>
                <rewrite>
                    <sales_order_view>Abc_Xyz_Block_Adminhtml_Sales_Order_View</sales_order_view>
                </rewrite>
            </adminhtml>
        </blocks>
        <helpers>
            <abc_xyz>
                <class>Abc_Xyz_Helper</class>
            </abc_xyz>
        </helpers>
        <resources>
            <abc_xyz_setup>
                <setup>
                    <module>Abc_Xyz</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
        </abc_xyz_setup>
    </resources>
    <events>
        <sales_convert_quote_item_to_order_item>
            <observers>
                <britvic_extend_observer>
                    <type>singleton</type>
                    <class>abc_xyz/observer</class>
                    <method>saveOrderItemData</method>
                </britvic_extend_observer>
            </observers>
        </sales_convert_quote_item_to_order_item>

        <sales_quote_add_item>
            <observers>
                <xyz_data_save_quote>
                    <type>singleton</type>
                    <class>abc_xyz/observer</class>
                    <method>saveXyzDataInQuoteItem</method>
                </xyz_data_save_quote>
            </observers>
        </sales_quote_add_item>

        <catalog_product_load_after>
            <observers>
                <extra_options>
                    <type>model</type>
                    <class>abc_xyz/observer</class>
                    <method>catalogProductLoadAfter</method>
                </extra_options>
            </observers>
        </catalog_product_load_after>
    </events>
    <template>
        <email>
            <custom_email_spspdfexport>
                <label>SPS Export PDF Email</label>
                <file>sps_exportpdf_email.html</file>
                <type>html</type>
            </custom_email_spspdfexport>
        </email>
    </template>
</global>
<crontab>
    <jobs>
        <sps_orders_pdfexport>
            <schedule>
                <!--<cron_expr>0 23 * 12 *</cron_expr>-->
            </schedule>
            <run>
                <model>abc_xyz/pdfexports::exportPdfsAndEmail</model>
            </run>
        </sps_orders_pdfexport>
    </jobs>
</crontab>
<frontend>
    <routers>
        <abc_xyz>
            <use>standard</use>
            <args>
                <module>Abc_Xyz</module>
                <frontName>xyz</frontName>
            </args>
        </abc_xyz>
    </routers>
    <layout>
        <updates>
            <abc_xyz>
                <file>abc/xyz.xml</file>
            </abc_xyz>
        </updates>
    </layout>
</frontend>
<admin>
    <routers>
        <abc_xyz>
            <use>admin</use>
            <args>
                <module>Abc_xyz_Adminhtml</module>
                <frontName>xyz</frontName>
            </args>
        </abc_xyz>
    </routers>
</admin>

<adminhtml>
    <layout>
        <updates>
            <xyz_tab>
                <file>xyz.xml</file>
            </xyz_tab>
        </updates>
    </layout>
    <events>
        <catalog_product_save_after>
            <observers>
                <xyz_save_product_data>
                    <type>singleton</type>
                    <class>abc_xyz/observer</class>
                    <method>saveProductXyzData</method>
                </xyz_save_product_data>
            </observers>
        </catalog_product_save_after>
    </events>
</adminhtml>

and adminhtml.xml

    <?xml version="1.0"?>
<config>
    <menu>
        <abc_xyz translate="title" module="abc_xyz">
            <title>Xyz</title>
            <sort_order>90</sort_order>
            <children>
                <types translate="title" module="abc_xyz">
                    <title>Manage Types</title>
                    <action>xyz/types/</action>
                    <sort_order>10</sort_order>
                </types>
                <associations translate="title" module="abc_xyz">
                    <title>Manage Associations</title>
                    <action>xyz/associations/</action>
                    <sort_order>20</sort_order>
                </associations>
                <!--<sandbox translate="title" module="abc_xyz">
                    <title>Sandbox</title>
                    <action>xyz/sandbox/</action>
                    <sort_order>30</sort_order>
                </sandbox>-->
            </children>
        </abc_xyz>
    </menu>

<acl>
    <resources>
        <admin>
            <children>
                <system>
                    <children>
                        <config>
                            <children>
                                <xyz_configuration>
                                    <title>Xyz</title>
                                </xyz_configuration>
                            </children>
                        </config>
                    </children>
                </system>
            </children>
        </admin>
    </resources>
</acl>

And Grid.php

    <?php

class Abc_Xyz_Block_Adminhtml_Types_Grid extends Mage_Adminhtml_Block_Widget_Grid {

    public function __construct() {
    parent::__construct();
    $this->setId('abc_xyz_grid');
    $this->setDefaultSort('entity_id');
    $this->setDefaultDir('DESC');
    $this->setSaveParametersInSession(true);
    $this->setUseAjax(true);
}

protected function _prepareCollection() {
    $collection = Mage::getModel('abc_xyz/types')->getCollection();

    $this->setCollection($collection);
    parent::_prepareCollection();
    return $this;
}

protected function _prepareColumns() {
    $helper = Mage::helper('abc_xyz');
    $currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);

    $showOptionsTypesSelect = Mage::getModel('abc_xyz/types')->showOptionsTypesSelect();

    $this->addColumn('entity_id', array(
        'header' => $helper->__('Entity ID'),
        'index' => 'entity_id'
    ));

    $this->addColumn('name', array(
        'header' => $helper->__('Name'),
        'index' => 'name',
        'type' => 'text'
    ));

    $this->addColumn('show_in', array(
        'header' => $helper->__('Show In'),
        'index' => 'show_in',
        'type' => 'options',
        'options' => $showOptionsTypesSelect
    ));

    return parent::_prepareColumns();
}

    public function getRowUrl($row) {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }

}

Types.php

class Abc_Xyz_Block_Adminhtml_Types extends Mage_Adminhtml_Block_Widget_Grid_Container {

public function __construct() {
    $this->_blockGroup = 'abc_xyz';
    $this->_controller = 'adminhtml_types';
    $this->_headerText = Mage::helper('abc_xyz')->__('Types');
    parent::__construct();
    }

}


app/design/adminhtml/default/default/layout/xyz.xml

here I can't see my block, if it is not here how my view is block/grid is being created.

    <?xml version="1.0"?>
<layout>
    <adminhtml_catalog_product_edit>
        <reference name="product_tabs">
            <action method="addTab">
                <name>abc_xyz</name>
                <block>abc_xyz/adminhtml_catalog_product_edit_tab</block>
            </action>
        </reference>
    </adminhtml_catalog_product_edit>
    <adminhtml_sales_order_view>
        <reference name="head">
            <action method="addItem">
                <type>skin_js</type>
                <name>js/jquery-1.10.2.min.js</name>
            </action>
            <action method="addItem">
                <type>skin_js</type>
                <name>js/jquery-ui-1.10.4.min.js</name>
            </action>
            <action method="addItem">
                <type>skin_css</type>
                <name>jquery-theme/ui-lightness/jquery-ui-1.10.4.min.css</name>
            </action>
            <action method="addItem">
                <type>skin_js</type>
                <name>js/jquery-noconflict.js</name>
            </action>
            <action method="addItem">
                <type>skin_js</type>
                <name>js/xyz.js</name>
            </action>
            <action method="addItem">
                <type>skin_css</type>
                <name>xyz.css</name>
            </action>
        </reference>
        <reference name="left">
            <reference name="sales_order_tabs">
                <reference name="order_tab_info">
                    <action method="unsetChild">
                        <name>order_items</name>
                    </action>
                    <block type="adminhtml/sales_order_view_items" name="order_items" template="xyz/sales/order/view/items.phtml">
                        <action method="addItemRender">
                            <type>default</type>
                            <block>adminhtml/sales_order_view_items_renderer_default</block>
                            <template>xyz/sales/order/view/items/renderer/default.phtml</template>
                        </action>
                        <action method="addColumnRender">
                            <column>qty</column>
                            <block>adminhtml/sales_items_column_qty</block>
                            <template>sales/items/column/qty.phtml</template>
                        </action>
                        <action method="addColumnRender">
                            <column>name</column>
                            <block>adminhtml/sales_items_column_name</block>
                            <template>sales/items/column/name.phtml</template>
                        </action>
                        <action method="addColumnRender">
                            <column>name</column>
                            <block>adminhtml/sales_items_column_name_grouped</block>
                            <template>sales/items/column/name.phtml</template>
                            <type>grouped</type>
                        </action>
                    </block>
                </reference>
            </reference>
        </reference>
    </adminhtml_sales_order_view>
</layout>

I have addedd following under layout in app/design/adminhtml/default/default/layout/xyz.xml

    <adminhtml_types_edit_edit>
<reference name="content">
    <block type="abc_xyz/adminhtml_types_edit_tab" name="abc_xyz_types" />
</reference>

not working

enter image description here

  • add your code too.. – Qaisar Satti Mar 21 '16 at 12:45
  • Please add mgento version on question tag thus user can understand – Amit Bera Mar 21 '16 at 12:47
  • @Qaisar Satti that is more complex, I try – Abdul Ghaffar Mar 21 '16 at 13:11
  • i am asking about gridAction() code – Qaisar Satti Mar 21 '16 at 13:14
  • @@Qaisar Satti done – Abdul Ghaffar Mar 21 '16 at 13:27
2

After a lot of debugging, finally I got it, public function getGridUrl(){......} was missing in Grid.php So in grid class

class Abc_Xyz_Block_Adminhtml_Types_Grid extends Mage_Adminhtml_Block_Widget_Grid 

add following function,

    public function getGridUrl() {
    return $this->getUrl('*/*/grid', array('_current' => true));
}

after adding this, following function is being called in controller to just refresh the gridview, with out refreshing full page(header+footer+ girdview).

public function gridAction() {
$this->loadLayout();
$this->getResponse()->setBody(
        $this->getLayout()->createBlock('abc_xyz/adminhtml_types_grid')->toHtml()
);
| improve this answer | |
1

Below code is being called twice

 $this->getLayout()->createBlock('abc_xyz/adminhtml_types')->toHtml()

once in indexAction and second time in gridAction.
This seems to be the issue.

| improve this answer | |
  • As I said in comment gridAction is never being called, – Abdul Ghaffar Mar 21 '16 at 13:46
  • If comment out this portion or whole function, it is working same – Abdul Ghaffar Mar 21 '16 at 13:46
  • Paste xml code as well. – Anshu Mishra Mar 21 '16 at 14:21
  • xml's are added – Abdul Ghaffar Mar 22 '16 at 5:21
  • Also add code for xyz.xml that you have mentioned in adminhtml layout config.xml – Anshu Mishra Mar 22 '16 at 6:40
1

I think the problem is with your gridAction. It's not displaying twice, but it is breaking.

You must have block_adminhtml_types_grid class to show your grid.

Then change gridAction as follow:

public function gridAction()
{
    $this->loadLayout();
    $this->getResponse()->setBody(
        $this->getLayout()->createBlock('abc_xyz/adminhtml_types_grid')->toHtml()
    );
}

This should work.

UPDATE

It's also related to your Types.php file, however, I don't know how you have written.

Your Types.php should be like this:

class Abc_Xyz_Block_Adminhtml_Types extends Mage_Adminhtml_Block_Widget_Grid_Container
{

    /**
     * Block constructor
     */
    public function __construct()
    {
        $this->_blockGroup = 'abc_xyz';
        $this->_controller = 'adminhtml_types';
        $this->_headerText = Mage::helper('abc_xyz')->__('Your Header');

        parent::__construct();

    }
}
| improve this answer | |
  • Not working, it never comes in gridAction()... – Abdul Ghaffar Mar 22 '16 at 5:40
  • Can you add your Types.php to your question. – Adarsh Khatri Mar 22 '16 at 5:43
  • I think I am doing alright, '$this->_blockGroup = 'types'; should be ' $this->_blockGroup = 'abc_xyz';, if you look into inchoo – Abdul Ghaffar Mar 22 '16 at 6:41
  • @AbdulGhaffar Yes, my mistake, now corrected. – Adarsh Khatri Nov 3 '16 at 22:24

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.