2

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?

4
  • please update your code of that function – Keyul Shah Jan 21 '14 at 9:44
  • please post the layout handles for your grid page and for the ajax request for filtering. I have a hunch you are missing the form key in the layout handle for the filter request. – Marius Jan 21 '14 at 9:47
  • @Marius - layout handles posted, I didn't set up any ajax requests for applying the filters, I just used $this->setUseAjax(true); to enable ajax filtering. – Moose Jan 21 '14 at 9:54
  • @KeyulShah - you mean upload? – Moose Jan 21 '14 at 9:56
3

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();
}
2
  • Absolutely spot on, solved the issue :) Thanks very much! Quick question: Does this meen a need a layout handler for both the index & the grid? – Moose Jan 21 '14 at 10:42
  • 1
    Yes. They are 2 separate actions. – Marius Jan 21 '14 at 10:45
0

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.

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.