Hi list,
I have a content type with multiple fields (name, tel, email, ...). I have created a view to list all nodes of this content type. I able to sort this view by names, tel, ... But now, I want to filter this view by ONE filter textbox and not one for name, an other for tel, ...
How can I do that ?
I try to use custom text to concatenate all fields but I can't filter my view on custom text field !
I have 2 solutions in mind. Create my own filter or concatenate cck fields into one and filter on it. But I don't know how do that.
Do you have some idea ? Or how can I do that ?
Thanks in advance for your help.
You might try enabling the search module and exposing the search terms filter. This should work on all indexed content (including CCK). However, I don't think it matches partial strings.
On Tue, Sep 21, 2010 at 12:57 AM, ceooph+drupallist@gmail.comceooph%2Bdrupallist@gmail.com <ceooph+drupallist@gmail.com ceooph%2Bdrupallist@gmail.com> wrote:
Hi list,
I have a content type with multiple fields (name, tel, email, ...). I have created a view to list all nodes of this content type. I able to sort this view by names, tel, ... But now, I want to filter this view by ONE filter textbox and not one for name, an other for tel, ...
How can I do that ?
I try to use custom text to concatenate all fields but I can't filter my view on custom text field !
I have 2 solutions in mind. Create my own filter or concatenate cck fields into one and filter on it. But I don't know how do that.
Do you have some idea ? Or how can I do that ?
Thanks in advance for your help.
-- [ Drupal support list | http://lists.drupal.org/ ]
Hi,
Below is a example how you can use the views api to make what you want:
<code> /** * Definning the form */ function filter_form(){ // Get the filter information of your view $view = views_get_view(COGEAE_SAD_ALUNO_VIEW); $view->set_display(COGEAE_SAD_ALUNO_VIEW_DISPLAY_LISTA); $filters = &$view->display_handler->options['filters']; $options = array(); foreach($filters as $filter){ $options[$filter->id] = $filter->field; } $form = array(); $form['filter_type'] = array( '#title' => t('Filter'), '#type' => 'select', '#options' => array('title' => t('Nome')), '#default_value' => 'nome' ); $form['filter_query'] = array( '#title' => t('Text'), '#type' => 'textfield', ); $form['submit'] = array( '#title' => t('Search'), '#type' => 'submit', '#value' => 'Filtrar' );
return $form;
} </code>
In this case, COGEAE_SAD_ALUNO_VIEW and COGEAE_SAD_ALUNO_VIEW_DISPLAY_LISTA are the names of the view and the display. On submit method you have to do the same as the search module, and do a redirect on your data:
<code> /** * Receiving the form information */ function filter_form_submit($form, &$form_state){ $values = $form_state['values']; $filter_type = $values['filter_type']; $filter_query = $values['filter_query']; $form_state['redirect'] = "phonebook/search/results/{$filter_type}/{$filter_query}"; } </code>
Now you can filter the information using the parameters and render the view:
<code> /** * Using the views filter dinamically to filter you content */ function search_phonebook_results($filter_type = 'title', $filter_value = ''){ $view = views_get_view(COGEAE_SAD_ALUNO_VIEW); $view->set_display(COGEAE_SAD_ALUNO_VIEW_DISPLAY_LISTA); $filters = &$view->display_handler->options['filters']; $filters[$filter_type]['value'] = $filter_value; $view->pre_execute(); $view_content = $view->display_handler->preview(); $view->post_execute(); return $view_content; } </code>
I hope this help.
Att,
Pablo Lacerda de Miranda Analista de Sistemas Pontifícia Universidade Católica de São Paulo pablolmiranda@gmail.com +55 11 8701-1086
I make a little mistake on the past code, just use $filter['id'] beside $filter->id. $filter is a array not a object.
Att,
Pablo Lacerda de Miranda Analista de Sistemas Pontifícia Universidade Católica de São Paulo pablolmiranda@gmail.com +55 11 8701-1086
Le 21/09/2010 18:14, Ted a écrit :
Another approach is to use the computed_field module to create a computed field that stores all the values from the other fields, then add that field as a filter. It's a hack, but for small datasets it won't affect performance.
Ted
On 9/21/2010 3:18 AM, Carl Wiedemann wrote:
You might try enabling the search module and exposing the search terms filter. This should work on all indexed content (including CCK). However, I don't think it matches partial strings.
On Tue, Sep 21, 2010 at 12:57 AM, ceooph+drupallist@gmail.com mailto:ceooph%2Bdrupallist@gmail.com <ceooph+drupallist@gmail.com mailto:ceooph%2Bdrupallist@gmail.com> wrote:
Hi list, I have a content type with multiple fields (name, tel, email, ...). I have created a view to list all nodes of this content type. I able to sort this view by names, tel, ... But now, I want to filter this view by ONE filter textbox and not one for name, an other for tel, ... How can I do that ? I try to use custom text to concatenate all fields but I can't filter my view on custom text field ! I have 2 solutions in mind. Create my own filter or concatenate cck fields into one and filter on it. But I don't know how do that. Do you have some idea ? Or how can I do that ? Thanks in advance for your help. -- [ Drupal support list | http://lists.drupal.org/ ]
Hi,
It's very helpful. Thank you !!!