If you’ve recently added a grid into your module and you’re experiencing issues when sorting or filtering like this:

Screen Shot 2014-03-12 at 09.50.51

This is because the Ajax request is trying to reload the same page you’re on. One way of resolving this would be to override the grid URL through the getGridUrl() function and then creating an entirely new action, with potentially a new layout entry or by calling the block directly. If you’re wanting to use this method you can find out exactly how here.

By default the Mage_Adminhtml_Block_Widget_Grid contains the following code to determine the grid URL.

This piece of code is telling the grid to use the current URL as the grids URL. Obviously the current URL would be the grid container including the header and footer which is causing the issues we’re seeing in the screenshot.

We can easily resolve this with 4 lines of code added into the controller action as follows.

This checks to see whether the request is done via an Ajax call and then returns the contents of the grid as HTML. You’d need to add this at the top of your action as follows.

This is just an example and you’ll most likely have a different action name, and other code within that action.

Dave Macaulay
Dave Macaulay
I'm an enthusiastic, slightly eccentric Magento developer who bores with the idea of another basic brief.