Drupal 7 Views - 如何使暴露过滤器成为唯一数据值的下拉列表

时间:2013-08-29 18:11:08

标签: drupal-7 drupal-views

我正在使用数据模块来搜索和过滤表数据。我正在使用视图在具有3个暴露过滤器的表中显示数据。

我希望用户从3个过滤器中的2个中选择特定值。但我目前只能显示允许用户键入值的文本框。

2 个答案:

答案 0 :(得分:2)

您需要查看hook_views_pre_render()。首先与devel模块中的dpm()一起使用它来探索视图结构。然后,您可以在发送之前直接更改视图(及其过滤器)以进行渲染。我建议使用php函数,比如array_unique()或你自己的自定义函数来遍历并独特地获得你的结果。

mymodule_views_pre_render(&$view) {
  // make sure devel module is turned on first, then take this out when you're
  // done exploring the view results
  dpm($view);
  // this part is pseudocode, I haven't memorized the view structure, but dpm() will
  // show you what to actually put here
  if( $view->name == "my_target_view_machine_name" ) {
    // do your uniquefying here
  }
}

答案 1 :(得分:1)

在为视图添加曝光过滤器时,drupal为您提供了两个选项(过滤器类型公开):单过滤器和分组过滤器,如果选择分组过滤器,它将允许您选择所需的小部件类型。(收音机/选择)

相关问题