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.
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)
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.
Ok, you can try ELT function.
SELECT …. ELT(month,'Enero','Febrero','Marzo',…,'Diciembre') as month …. FROM table
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.
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");
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.
Yes, you will need to set constant values.
e.g.
$str = "1:Jan;2:Feb;3:Mar…..";
$col["editoptions"] = array("value"=>$str);