Magento - 使用ajax的网格过滤器重新加载整个页面
我在 magento admin 中使用网格(扩展 Mage_Adminhtml_Block_Widget_Grid
)来显示数据库表的内容。我在其他一些模块中看到,在构造函数中可以设置一个选项来使用 ajax 重新加载而不是页面重新加载
这是我的构造函数:
public function __construct() {
parent::__construct();
$this->setId('myGrid');
$this->setSaveParametersInSession(true);
$this->setVarNameFilter('my_filter');
$this->setUseAjax(true);
}
但是当我单击网格过滤器并单击搜索按钮时,它会重新加载网格 div 内的整个页面(包括页眉、页脚...)。
有什么想法为什么会出现这种情况吗?
I'm using a grid in magento admin (extending Mage_Adminhtml_Block_Widget_Grid
) to display the content of a database table. I saw in some other modules that there's an option to be set in the constructor to use ajax reloads instead of page reloads
this is my constructor:
public function __construct() {
parent::__construct();
$this->setId('myGrid');
$this->setSaveParametersInSession(true);
$this->setVarNameFilter('my_filter');
$this->setUseAjax(true);
}
but when I click the filter of the grid and click the search button, it reloads the WHOLE page (including header, footer,...) INSIDE the grid div.
Any ideas why this is the case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我找到了解决方案:
首先,我必须将以下函数添加到网格类,
然后每个 ajax 调用将被发送到此 url(以及相应的控制器操作),而不是页面 url。
然后我将以下内容添加到布局 XML 文件中:
这会覆盖根元素并仅显示网格块。因此我的 ajax 调用只会加载更新的网格本身,不会包含页眉、页脚等。
I found the solution:
First I had to add the following function to the grid class
each ajax call will then be sent to this url (and the corresponding controller action) rather then the pages url.
then I added the following bit to the layout XML file:
this overwrites the root element and displays only the grid block. hence my ajax call will only load the updated grid itself and won't include header, footer, etc.
您还可以向管理控制器添加“gridAction”方法,而不是创建布局 xml
假设:
Block Path :
/app/code/local/{命名空间}/{模块}/Block/Adminhtml/{模块}/Grid.php
You could also add a "gridAction" method to your admin controller instead of creating a layout xml
Assuming:
Block Path :
/app/code/local/{Namespace}/{Module}/Block/Adminhtml/{Module}/Grid.php
将以下代码添加到 __construct() 函数中:
app/code/local/[Name_Space]/[Module_Name]/Block/Adminhtml/[Module_Name]/Grid.php 文件。
现在添加以下代码该文件最后的函数。
现在最后在:
app/code/local/[Name_Space]/[Module_Name]/controllers/Adminhtml/[Module_Name]Controller.php 文件中添加以下函数。
由 Nirav 提供卡迪亚
Add follwing code into __construct() function in :
app/code/local/[Name_Space]/[Module_Name]/Block/Adminhtml/[Module_Name]/Grid.php file.
Now Add following function at last of this file.
Now Add following function at last in :
app/code/local/[Name_Space]/[Module_Name]/controllers/Adminhtml/[Module_Name]Controller.php file.
Courtesy : Nirav Kadiya
Nirav Kadiya 几乎适合我,但我在管理控制器中创建这样的 gridAction 函数:
并将其包含在 de Grid 文件中
The Nirav Kadiya almost works for me but I create the gridAction function like this in the Admin Controller:
And include this in de Grid file