How to make the custom grid url in the Magento

How to make the custom grid url in the Magento

September 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to make the custom grid url in the Magento

Customizing Edit Grid URLs in Magento: A Comprehensive Guide

As a developer working on a Magento project, you may find yourself needing to customize the URL structure for your grid views, especially when dealing with edit links. In this post, we’ll explore how to dynamically pass additional parameters to these URLs using a custom module as an example.

The Challenge at Hand

Our user is currently creating a custom module and displaying database values in a grid view. The edit link URLs generated by Magento have the following structure:

http://example.com/index.php/xyz/adminhtml_mymodule/edit/id/32/key/cf9639d403c328b26678fb7fa8f78cc5/

The user wants to pass an additional parameter, let’s say store_id, dynamically from the current row data. Currently, they are manually setting this parameter in the grid configuration as follows:

'url' => array('base'=>'*/*/edit','params'=>array('store'=>5)),

This results in URLs like:

http://example.com/index.php/xyz/adminhtml_mymodule/edit/id/32/store/5/key/cf9639d403c328b26678fb7fa8f78cc5/

However, the user wants to pass the store_id parameter dynamically based on the current row’s data.

Solving the Problem: A Step-by-Step Approach

To achieve this, we’ll need to modify the grid configuration and use a custom getter for the URL parameters. Here’s how you can do it:

  1. Create a Custom Getter Method

In your grid class, create a new public method that returns an array containing the dynamic store_id parameter.

public function getUrl()
{
    $row = $this->getRow();
    $urlParams = array('id' => $row->getId(), 'key' => Mage::helper('core')->getRandomString(32));
    if ($row->getStoreId()) {
        $urlParams['store'] = $row->getStoreId();
    }
    return $this->getUrlByRoute('*/*/edit', $urlParams);
}

This method retrieves the current row data and checks if a store_id is available. If it is, the parameter is added to the $urlParams array.

  1. Update the Grid Configuration

In your grid configuration XML file (usually located in app/code/local/Your/Namespace/etc/adminhtml.xml), update the edit_url field as follows:

<action>
    <type>grid</type>
    <controller>mymodule/adminhtml_mymodule</controller>
    <forwarded_controller>mymodule/adminhtml_mymodule</forwarded_controller>
    <url_path>edit</url_path>
    <url_model>cms/page/url</url_model>
    <update_handle>mymodule_gridjs</update_handle>
    <params>
        <param name="store">null</param>
    </params>
    <sort_order>0</sort_order>
</action>

Note that we’ve removed the store parameter from the params section to allow our custom getter method to handle it.

Best Practices and Further Optimizations

When working with grid URLs in Magento, here are some best practices to keep in mind:

  • Always use the getUrlByRoute() method provided by Mage for generating URLs. This ensures that the URL is properly encoded and follows Magento’s routing rules.
  • If you need to pass multiple dynamic parameters, you can follow a similar approach as shown above, adding each parameter to the $urlParams array in your custom getter method.
  • Remember to clear the cache after making changes to grid configurations or URLs.

Conclusion

Customizing grid URLs in Magento requires a deep understanding of how the system generates these links and where you can inject your own logic. By creating a custom getter method for the URL parameters and updating the grid configuration, we’ve demonstrated how to pass dynamic data from the current row into the edit link URL.

Remember to test your changes thoroughly to ensure they do not break any existing functionality or create security vulnerabilities. Always follow Magento’s best practices for code organization and performance optimization.

For more detailed guides on developing custom modules in Magento, I recommend checking out our comprehensive tutorials at Laravel Company.

Happy coding!

Database Extensions Admin Configuration

Our network