|
|
|
Rank: Member
Groups: Registered
Joined: 7/15/2010 Posts: 12
|
Hello. I'm working with dates formated like this in my database: dmY. There is no separator. I used a custom formatter to display thoses dates. Code: $grid->setColProperty("date", array("formatter"=>"js:colDate")); $myformat = <<<FORMATFREIGHT function colDate (cellValue, options, rowdata) { var un = cellValue.substr(0, 2); var deux = cellValue.substr(2, 2); var trois = cellValue.substr(4, 4); return un+"/"+deux+"/"+trois; } FORMATFREIGHT;
This is working very well. The issue is when I try to sort the column. How may I do to sort them as dates? I'm using the following code, but it don't seems to work. Code: // set the user date format to d/m/Y $grid->setUserDate('d/m/Y');
// tell the grid which field is date $grid->datearray = array('date');
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 10/15/2009 Posts: 379
|
Hello Pierre, Can you please try with formatter date and with formatoptions for src and new formats, e.g. something similar to this (but modified to match your case) Code:$grid->setColProperty("RequiredDate", array( "formatter"=>"date", "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y"), ) ); Kind Regards, Rumen Stankov (MCPD) Trirand Inc.
|
|
|
|
Rank: Member
Groups: Registered
Joined: 7/15/2010 Posts: 12
|
Hello Rumen. I tried this: Code: $grid->setColProperty("MyDate", array( "formatter"=>"date", "formatoptions"=>array("srcformat"=>"dmY","newformat"=>"d/m/Y"), ) ); $grid->setColProperty("MyDate", array("label"=>"Date entrée", "width"=>100, "searchoptions"=>array("sopt"=>array("cn")) ) );
A while ago I was using this: Code: $grid->setColProperty("MyDate", array("label"=>"Date entrée", "width"=>100, "searchoptions"=>array("sopt"=>array("cn")), "formatter"=>"date", "formatoptions"=>array("srcformat"=>"dmY", "newformat"=>"d/m/Y") ) );
The result is the same, with an input like this date : 14052007 I have the following output : 01/01/1970 It seems that when there is no separator in the date field, the date formater don't work. That's why I tried a custom formater. Regards, Pierre
|
|
|
|
Rank: Administration
Groups: Registered
Joined: 1/8/2010 Posts: 636 Location: Sofia, Bulgaria
|
Hello, How is the problematic date field defined into the DataBase? (please if possible do a table dump) Which database is used? Kind Regards Tony Tomov TriRand Inc
|
|
|
|
Rank: Member
Groups: Registered
Joined: 7/15/2010 Posts: 12
|
Hello Tony,
I'm using MySQL: 5.x
`MyDate` varchar(8) DEFAULT NULL,
Into the database my values are like this 01122007
With a custom formater, the output is ok but the sorting is not.
Regards, Pierre.
|
|
|
|
Rank: Administration
Groups: Registered
Joined: 1/8/2010 Posts: 636 Location: Sofia, Bulgaria
|
Hello, I think that your sorting will not work correct, since the field is varchar and you want to interpret it as date. The grid recognizes this field as varchar and nothing more. This is equivalent of "SELECT MyDate, .... WHERE .... ORDER BY MyDate"; If you run this command into the SQL console you will have the same result. One possible solution maybe is to use CAST function, where the database should convert the field to date field. Kind Regards Tony Tomov TriRand Inc
|
|
|
|
Rank: Member
Groups: Registered
Joined: 7/15/2010 Posts: 12
|
Hello,
Thanks for the answer. I'll do like you said.
Btw TriRand team did a great job with jqGrid, thanks for that too.
Regards, Pierre.
|
|
|
|
Guest
|
YAFPro Theme Created by Jaben Cargman (Tiny Gecko)Powered by YAF 1.9.3 |
YAF © 2003-2009, Yet Another Forum.NETThis page was generated in 0.226 seconds.