Question

I have set up a custom adminhtml grid for a model of mine, which works fine. I've added a mass-delete function which allows the user to tick multiple entries and then delete them.

This function works as intended, however, as soon as a user applies a filter on the page, i.e tries to filter by a certain date AND THEN tries to use mass delete, it simply throws the user to the admin dashboard

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

Layout handles

<adminhtml_availability_index>
    <reference name="content">
        <block type="company_module/adminhtml_availability" name="company_module_availability" />
    </reference>
    <reference name="js">
        <block type="core/template" template="module/availability-js.phtml" />
    </reference>
</adminhtml_availability_index>

Anybody have any ideas?

Was it helpful?

Solution

If you setUseAjax(true) you need to have an url where the ajax is send and a layout handle for it. Something like this:

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

A new layout handle

<adminhtml_availability_grid>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="company_module/adminhtml_availability_grid" name="company_module_availability_grid" />
    </block>
</adminhtml_availability_grid>

And a new method in your controller

public function gridAction() {
    $this->loadLayout()->renderLayout();
}

OTHER TIPS

A new feature in Magento 1.4.1. is that any filtering done on the Sales > Orders page is now updated via an AJAX call when hitting submit. Unfortunately this has an unindented side-effect: after any ajax updates the mass-actions (Cancel, Hold, Print Invoices, Print Packingslips, etc) will not work. Instead you will be thrown back to the Dashboard (or whatever else your current users start page in the admin area is).

After an ajax update Magento doesn’t load the complete layout of the page. However in the layout it keeps a form key to authenticate the submission of the request. Since this is now missing it will “decline” the request from the mass-action and you are thrown back to the dashboard.

To fix this issue you can edit app/design/adminhtml/default/default/template/widget/grid/massactions.phtml and change

<?php echo $this->getBlockHtml('formkey')?>

to

<div><input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /></div>

On a sidenote: after being thrown back to the dashboard and visiting Sales > Orders for a second time it will remember your previous selection. And since it now has done a full page load the mass-action will succeed.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top