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.
  • Henners

    Hi Dave, I’m still struggling with this a little, I’m not much of a Magento Dev. I’ve copied the file Grid.php into my Local folder, So now it’s at local/Mage/Adminhtml/Block/Widget/Grid.php

    And I’ve changed the conditional into the getGridUrl controller

    But I don’t understand how to “add this at the top of your action” with the second portion of the code. Can you enlighten?

    Many Thanks this has been bugging me for ages.

    • daavem

      Hey Henners, sorry I didn’t get back to you sooner, I’ve been having some interesting issues with Disqus.

      So that piece of code will need to be added within the controller action for that specific grid. Above any other logic within the action, this will ensure the grid is returned correctly when Magento requests the filters.