Month Field

QuestionsMonth Field
Alfonso Cabrera asked 10 years ago

Hi!

I would like to know if this is possible.

Database Table
Id
month
year

Suppose we have the following information in the table.

Id month year
1 1 2001
2 3 2002

I want to show the filed month in my grid as follows:

Id month year
1 Jan 2001
2 Mar 2002

Thank you.

8 Answers
Abu Ghufran answered 10 years ago

In select_command you can specify query and use mysql functions for this conversion.

SELECT MONTHNAME(STR_TO_DATE(month, '%m'));
Source: http://stackoverflow.com/questions/7027129/mysql-monthname-from-numbers

It return full month name, not 3 char short name. Perhaps you can apply substr:
SELECT SUBSTR(MONTHNAME(STR_TO_DATE(month,'%m')),1,3)

Alfonso Cabrera answered 10 years ago

Thank you, if I wanted to use it with the Spanish localization. The result maybe January, February, March and I need it to be like: Enero, Febrero, Marzo.

Thanks for your help.

Abu Ghufran answered 10 years ago

Ok, you can try ELT function.

SELECT …. ELT(month,'Enero','Febrero','Marzo',…,'Diciembre') as month …. FROM table

Alfonso Cabrera answered 9 years ago

Hi!

Thanks for your help.

This is my actual configuration for the column named mes

$col = array();
$col["title"] = "Mes"; // caption of column
$col["name"] = "mes"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
$str = $g->get_dropdown_values("SELECT ELT(mes,'Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic') as mes FROM vacaciones");
$col["stype"] = "select"; // enable dropdown search
$col["editoptions"] = array("value"=>$str);
$col["searchoptions"] = array("value" =>$str);
$col["formatter"] = "select"; // display label, not value
$col["width"] = 100;
$cols[] = $col;

When I execute the query in MySQL it returns the correct values but not inside the grid. I'm missing something?

Thanks for your support.

Abu Ghufran answered 9 years ago

It should be aliased as 'k' and 'v', like:

$str = $g->get_dropdown_values("SELECT mes as k, ELT(mes,'Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic') as v FROM vacaciones");

Alfonso Cabrera answered 9 years ago

Hi Abu!

Thank you, I still have just one more question. It displays the info as I need it, but it lists all the values of the all the rows in the drop down list.

It is possible to pick only the 12 values of the 12 months instead of having all the values that are in the table.

Let make myself clear.

Id mes
1 2
2 4
3 6
4 2
5 7

In the grid
1 Feb
2 Abr
3 Jun
4 Feb
5 Jul

When I want to pick a value from the dropdown list.

Feb
Abr
Jun
Feb
Jul

Should I put in the $col["editoptions"] = array("value"=>$str); the array of the 12 month values?

Thank you.

Abu Ghufran answered 9 years ago

Yes, you will need to set constant values.
e.g.

$str = "1:Jan;2:Feb;3:Mar…..";
$col["editoptions"] = array("value"=>$str);

Alfonso Cabrera answered 9 years ago

Thank you for your help.

Your Answer

17 + 3 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?