Custom Fields and Filters in Views2

Events happening in the community are now at Drupal community events on www.drupal.org.
kswan's picture

I have a case were I would like to add an SQL calculation to the SELECT clause of a Views2 query. For this specific case, I would like to add something like "(TO_DAYS(NOW) - TO_DAYS(field_due_date)) AS days_late". I am sure there would be other cases that would benefit from this feature as well, such as a UNIT_PRICE * QUANTITY.

I think that it would be useful for advanced site administrators to enter their custom SQL statement that would be inserted in the query. Similar functionality would apply to both Fields (SELECT clause)and Fiters (WHERE clause).

First, does this functionality already exist? If not, I am considering writing a patch or module.
Are there any design or security considerations that need to be discussed?

Comments

Nevermind, I found Views Custom Field

kswan's picture

I found a sweet module that does what I need. It allows PHP code to calculate a Views field instead of SQL functions.

The module is http://drupal.org/project/views_customfield.

To create a field in drupal 5

Riya_Nithal's picture

I have to add a select box in existing view...could you please help me...i am new in drupal

Do you mean you have to add a

herve's picture

Do you mean you have to add a filter to an existing view? In this case, you should use the UI administration of views.

yes...but i have to write

Riya_Nithal's picture

yes...but i have to write code for creating drop down list in form api

What do you want exactly to

herve's picture

What do you want exactly to do?
You want to alter the displayed values in an existing drop down list generated but views? Or you want to add programatically a totally new filter using the Form API?

Anyway, you should alter the "views_exposed_form"...

I have created a page-view

Riya_Nithal's picture

I have created a page-view and which displays some data...Actually i want to filter that data based on month rage..
Months should be displayed in a drop-down list..So, i have to create the drop-down list at the top of the page-view

Ok. I think you should make

herve's picture

Ok. I think you should make something like that without any snippet of code.
You should install the Date module : http://drupal.org/project/date

After that, a new type of filter will be available, the Date one. It allows to use filter values on date node fields and/or user date fields. You could generate month drop down list with this module.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: