Magento 禁用管理网格的过滤字段

发布于 2024-09-18 06:00:10 字数 183 浏览 5 评论 0原文

我有一个带有后端页面的自定义模块。在网格中,我将客户电子邮件显示为用户名。默认情况下,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

楠木可依 2024-09-25 06:00:10

将选项添加

    'filter' => false

到要在网格视图中删除过滤器的列(例如 app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php)

    $this->addColumn('email', array(
       'header'    => Mage::helper('module')->__('Email'),
       'align'     =>'left',
       'index'     => 'email',
       'filter' => false,
   ));

Add the option

    'filter' => false

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)

    $this->addColumn('email', array(
       'header'    => Mage::helper('module')->__('Email'),
       'align'     =>'left',
       'index'     => 'email',
       'filter' => false,
   ));
失去的东西太少 2024-09-25 06:00:10

我猜您的意思是“如何删除该列的字段,以便管理员t按该字段进行过滤”

如果是这样,我可以告诉您如何删除电子邮件字段。

打开 /app/code/local/Namespace/Module/Block/Adminthml/Module/Grid.php

在受保护函数 _prepareColumns() 的某处,您应该找到类似的内容:

  $this->addColumn('email', array(
      'header'    => Mage::helper('module')->__('Email'),
      'align'     =>'left',
      'index'     => 'email',
  ));

只需注释此行。

并注意,在整个类最开始的 __construct 方法中,你没有

  $this->setDefaultSort('email');

If so,将其更改为

$this->setDefaultSort('id'); // if you have an id field in your module.

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 :

  $this->addColumn('email', array(
      'header'    => Mage::helper('module')->__('Email'),
      'align'     =>'left',
      'index'     => 'email',
  ));

Just comment this lines.

And watch out that, in the __construct method at the very beginning of the whole class, you don't have

  $this->setDefaultSort('email');

If so, change it to

$this->setDefaultSort('id'); // if you have an id field in your module.
假情假意假温柔 2024-09-25 06:00:10

如果您的自定义表格中没有电子邮件列,那么我假设您通过将自定义表格加入到包含用户电子邮件地址的核心表格(例如 customer_entity)来创建网格。

当您过滤列时,Magento 使用列索引来生成 where 子句。在您的情况下,它将给出类似 WHERE email LIKE '%filter value%' 的内容,但它不会在您的自定义表中找到电子邮件。

您可以通过使用 filter_index 显式告诉 Magento 在构建 where 子句时使用哪个表和列来解决此问题。尝试类似的操作

$this->addColumn('email', array(
    'header'    => Mage::helper('module')->__('Email'),
    'index'     => 'email',
    'filter_index'          => 'core_table.email',
));

,其中 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 this

$this->addColumn('email', array(
    'header'    => Mage::helper('module')->__('Email'),
    'index'     => 'email',
    'filter_index'          => 'core_table.email',
));

where core_table is the table you are joining with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文