Date Format from MySql Timestamp

Hi,

I’m using grid version 3.0 Pro

I’m trying to format a date field in a grid. Date came from a mysql request throw a connector, the format looks like that : 2011-11-21 15:10:10

Using setDateFormat(%d-%m-%Y) doesn’t change how the date is displayed in the grid. It’s seem to be applied only if I pick-up a new date from the calendar.

code sample below

grid_commandes = panel_order.attachGrid();
grid_commandes.setIconsPath('./codebase/imgs/');
grid_commandes.setHeader( ["id", "Numéro", "Date", "Type", "Status", "Note" ]);
grid_commandes.setColTypes("ro,ron,dhxCalendar,ro,coro,ro");
grid_commandes.setDateFormat("%Y-%m-%d");

Do I done something wrong or setDateFormat is only applied to date selected from the calendar ?

Thanks by advance,

Mory

You can use 2nd parameter of setDateFormat() to define server side date format.

Ok, that’s work… great. Thanks a lot.

Is there a way to set dhxCalendar cell not editable ?

You can just use “ro” eXcell type.

Ok but setDateFormat is only applicable to dhxCalendar type, isn’t it ?

I have now another problem with setDateFormat on a subgrid. My code below :

Subgrid generated from a connector :

MySql query....

print('<rows>');   
	print('<head>');
        print('<column width="30" type="ro" align="right" color="#d5f1ff" sort="str">ar_id</column>');
        print('<column width="70" type="ro" align="center" color="#d5f1ff" sort="str">Number</column>');
	print('<column width="150" type="dhxCalendar" align="center" color="#d5f1ff" >Essai 1</column>');
	print('<column width="250" type="ro" align="left" color="#d5f1ff" sort="str">Note</column>');
        print('<settings>');
            print('<colwidth>px</colwidth>');
        print('</settings>');
    print('</head>');

 while($row=mysql_fetch_array($res)){
            print("<row id='".$row['ar_id']."'>");
            	print("<cell>");
                    print($row['ar_id']);  
                print("</cell>");
                print("<cell>");
                    print($row['ar_number']);  
                print("</cell>");
                print("<cell>");
                    print($row['ar_ess_a']);   
                print("</cell>");
                print("<cell>");
                    print($row['ar_note']);  
                print("</cell>");
             print("</row>");
        }
        print("</rows>");

Initialisation on client-side :

grid.attachEvent("onSubGridLoaded", function(subgrid) {
		subgrid.setStyle("font-weight:bold;", "", "");
		subgrid.setColumnHidden(0, true);
		subgrid.selectRow(0, true, true, true);
		subgrid.setDateFormat("%d-%m-%Y %h:%i:%s","%Y-%m-%d %h:%i:%s");
		return false; // block default behavior
	});

While setDateFormat is works on my grid, it does not on the subgrid.

Thanks by advance for your help.

Mory

Ok but setDateFormat is only applicable to dhxCalendar type, isn’t it ?
Yes, but you can format date on the server side and return data with necessary format. If you plan to have a lot of data, it will increase grid performance

While setDateFormat is works on my grid, it does not on the subgrid.
This is expected. You should apply setDateFormat() method for sub grid object:

subgrid.setDateFormat("%d-%m-%Y %h:%i:%s","%Y-%m-%d %h:%i:%s");

Doesn’t it work for you?

Yes, that’s what i do, but it doesn’t work…

Ok, i got it.

I put the setDateFormat() in onSubGridCreated instead of onSubGridLoaded

Thanks a lot for your help.

Mory