EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: wel on January 13, 2016, 07:00:02 PM



Title: Entering date and time into datetime field
Post by: wel on January 13, 2016, 07:00:02 PM
Hi,
I use MySQL "datetime" field to store date and time and I use inline grid editor and the column simply like this

Code:
 <th field="job_stamp" width="120" editor="datetimebox">Date and time</th>

The problem the drop down editor store date like that 1-14-2016 and database does not accept this format when I press save and then refresh I find the field become null again but if I enter the date manually like this 2016-14-1 I find it is stored normally !! how to fix this problem so user can use the drop down date and time combobox ?


Title: Re: Entering date and time into datetime field
Post by: jarry on January 13, 2016, 07:54:51 PM
You have to set the format of the datetimebox editor.
Code:
<th field="job_stamp" width="120" data-options="
editor:{
type:'datetimebox',
options:{
formatter: function(date){
...
},
parser: function(s){
...
},
//...
}
}
">Date and time</th>

Please refer to:

http://www.jeasyui.com/forum/index.php?topic=3545.0
http://www.jeasyui.com/forum/index.php?topic=4011.0


Title: Re: Entering date and time into datetime field
Post by: wel on January 14, 2016, 10:31:19 AM
Thanks jarry I used this code:

Code:
<th field="job_stamp" width="120" data-options="
                                    editor:{
                                        type:'datetimebox',
                                        options:{
                                            formatter: function(date){
                                                if (!(date instanceof Date)) date = new Date(date);
                                                var h = date.getHours();
                                                var M = date.getMinutes();
                                                var s = date.getSeconds();

                                                function _ff(v) {
                                                    return (v < 10 ? '0' : '') + v;
                                                };
                                                return _ff(date.getFullYear())+'-'+_ff(date.getMonth()+1)+'-'
                                                    +date.getDate() + ' ' + _ff(h)+':'+_ff(M)+':'+_ff(s);
                                            },
                                            parser: function(s){
                                                if ($.trim(s) == '') {
                                                    return new Date();
                                                }
                                                var dt = s.split(' ');
                                                var p1 = dt[0].split('-');
                                                var p2 = dt[1].split(':');
                                                return new Date(p1[0],p1[1]-1,p1[2],p2[0],p2[1],p2[2]);

                                            },
                                            required:true,

                                        }
                                    }
                                    ">Date and time
                                </th>