Magento 禁用管理网格的过滤字段
我有一个带有后端页面的自定义模块。在网格中,我将客户电子邮件显示为用户名。默认情况下,Magento 会向网格中的每一列添加一个过滤器。现在,当我尝试按客户的电子邮件进行过滤时,出现异常,提示我的自定义表没有电子邮件列。 Magento 试图在我的自定义表中找到它。我该如何解决这个问题,或者如何删除该列的字段,以便管理员无法按该字段进行过滤。 谢谢。
I have a custom module with a backend page. In the grid, I show the customer email as the user name. By default, Magento adds a filter to every column in the grid. Now, when I try to filter by the customer's email, I get an exception saying that my custom table doesn't have an email column. Magento is trying to find that in my custom table. How can I fix this problem, or how can I remove the field of that column so that the admin can't filter by that field.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将选项添加
到要在网格视图中删除过滤器的列(例如 app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php)
Add the option
to the column you want to remove the filter from in the grid view (e.g. app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php)
我猜您的意思是“如何删除该列的字段,以便管理员t按该字段进行过滤”
如果是这样,我可以告诉您如何删除电子邮件字段。
打开 /app/code/local/Namespace/Module/Block/Adminthml/Module/Grid.php
在受保护函数 _prepareColumns() 的某处,您应该找到类似的内容:
只需注释此行。
并注意,在整个类最开始的 __construct 方法中,你没有
If so,将其更改为
I guess you meant "how can I remove the field of that column so that the admin can ' t filter by that field"
If so, I can tell you how to remove the email field.
Open /app/code/local/Namespace/Module/Block/Adminthml/Module/Grid.php
Somewhere in the protected function _prepareColumns() you should find something like :
Just comment this lines.
And watch out that, in the __construct method at the very beginning of the whole class, you don't have
If so, change it to
如果您的自定义表格中没有电子邮件列,那么我假设您通过将自定义表格加入到包含用户电子邮件地址的核心表格(例如
customer_entity
)来创建网格。当您过滤列时,Magento 使用列索引来生成 where 子句。在您的情况下,它将给出类似
WHERE email LIKE '%filter value%'
的内容,但它不会在您的自定义表中找到电子邮件。您可以通过使用
filter_index
显式告诉 Magento 在构建 where 子句时使用哪个表和列来解决此问题。尝试类似的操作,其中
core_table
是您要加入的表。If you don't have an email column in your custom table, then I assume you're creating your grid by joining your custom table to a core table that contains the users email address, such as
customer_entity
.When you filter on a column, Magento uses the column index to produce the where clause. Which in your case will give something like
WHERE email LIKE '%filter value%'
, but it wont find email in your custom table.You might be able to fix this by using
filter_index
to explicitly tell Magento which table and column to use when building the where clause. Try something like thiswhere
core_table
is the table you are joining with.