ryansuitposungkono / openjs-grid

Automatically exported from code.google.com/p/openjs-grid
0 stars 0 forks source link

Problem displaying date as dd-mm-yy #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  dateFormat:'dd-mm-yy' ,set the sql table in phpmyadmin to DATE.

2.
3.

What is the expected output? What do you see instead?
expected output:saving input in dd-mm-yy format and displaying it correctly.

instead:00-00-00 is being displayed

What version of the product are you using? On what operating system?
1.8

Please provide any additional information below.
probably becuse the DATE in my sql is being saved in yy-mm-dd conversation 
isn't being done correctly - this is why 00-00-00 appears.
any idea where is the bug?

Original issue reported on code.google.com by ewolfson...@gmail.com on 5 Aug 2011 at 9:49

GoogleCodeExporter commented 9 years ago
This is funny I never caught this.
I actually never do a conversion.

What would need to happen is either in javascript or PHP, it would have to get 
the field marked as date, parse it into mysql format.

The best place to do this would be in grid.js on the big if else for 
"editType".  I would add

if(editType == "textarea") {

then add the functionality of

http://boonedocks.net/mike/archives/157-Formatting-a-Javascript-Date-for-MySQL.h
tml

Ill be adding this to the next release

thanks!

Original comment by Seancla...@gmail.com on 17 Aug 2011 at 4:24

GoogleCodeExporter commented 9 years ago

Original comment by Seancla...@gmail.com on 17 Aug 2011 at 4:25

GoogleCodeExporter commented 9 years ago
What timeframe are we looking at for the next release ?
Thanks.

Original comment by p.oconn...@wac.nsw.edu.au on 24 Sep 2011 at 5:31

GoogleCodeExporter commented 9 years ago
I had a go at getting this working today by hacking grid.js and it seems to 
work ok.
I basically did this:

At the top of grid.js set this value  so all my dates in the grid appear in 
this format

dateFormat:'dd-mm-yy'

then

In grid.js, after this block of code:

//----------------------------  begin snippet
if($(this)[0].type == "checkbox") {
   var val = $(this)[0].checked ? 1 : 0;
   // all other values can use .val()
}
//----------------------------  end snippet

I added this:

//----------------------------  begin snippet
else if($grid.data().columnOpts[col].editable == "date") {
var val = $(this).val();
var year = val.substring(6,10);
var month = val.substring(3,5);
var day = val.substring(0,2);
val = year + "-" + month + "-" + day;    
} 
//----------------------------  end snippet
This sets the date format (yes I know in hard coded form for now) 
from dd-mm-yyyy to the mySQL format of yyyy-mm-dd

I also had to do this in grid.js so that when the grid is initially rendered, 
it changes the
default mySQL format to my format of dd-mm-yyyy from yyyy-mm-dd.

After this block of code

//---------------------------  begin snippet
if(editType == "textarea") {
var $input = $('<textarea '+maxlength+' class="editableInput 
'+xtraClass+'"></textarea>');
} else {
var $input = $('<input '+maxlength+' class="editableInput '+xtraClass+'" 
type="text" />');
}   
//----------------------------  end snippet

I added this

//---------------------------  begin snippet
if(editType == "date") {
var year = $td.text().substring(0,4);
var month = $td.text().substring(5,7);
var day = $td.text().substring(8,10);
$input.val(day + "-" + month + "-" + year);
}
//----------------------------  end snippet

So basically, I had to make 2 changes, when the dates come out of mysql and 
when they go back in. As posted by Sean it was easiest to do it in grid.js, 
after the date is read from mysql and being rendered for the page, then also on 
the save event, when javascript is preparing to deliver the JSON data back to 
mysql via the php script.
I hope this helps - I will try and clean it up a bit so it is more maintainable 
based on the dateformat option set at the start of grid.js...

Original comment by p.oconn...@wac.nsw.edu.au on 24 Nov 2011 at 12:53

GoogleCodeExporter commented 9 years ago
Has this been fixed? That is to say what do i have to chagne in order to apply 
this to my table columns? I am using version 2.

Original comment by a110hur...@gmail.com on 24 May 2013 at 2:53