EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: wikusg on January 13, 2015, 12:04:41 AM



Title: Datebox default date
Post by: wikusg on January 13, 2015, 12:04:41 AM
Hi all

I'm using a datebox in an edatagrid. I do not want the datebox to set the value to today's date when clicking on the box, reason being that when editing the grid, the field is sometimes already populated and then the date is changed to today's date when clicking on the field to edit it.

Any help will be appreciated.

Thanks

Wikus


Title: Re: Datebox default date
Post by: stworthy on January 13, 2015, 08:47:43 AM
When editing a row, the editor's value depends on the corresponding field value. If the field value is empty or illegal, the datebox value will be set to the current day. Please confirm if the date field has a valid value. Of course, you can change the editor's value in 'onBeginEdit' event.
Code:
$('#dg').datagrid({
    onBeginEdit: function(index,row){
        var ed = $(this).datagrid('getEditor',{index:index,field:'datefield'});
        $(ed.target).datebox('setValue', '1/2/2014')
    }
});


Title: Re: Datebox default date
Post by: wikusg on January 13, 2015, 09:39:41 PM
Hi

The value is valid, but in the MySQL date format. I think that is where my problem occurs. I'm currently looking at changing the date format on the php side.

Thanks

Wikus


Title: Re: Datebox default date
Post by: ehussain on January 16, 2015, 12:25:35 PM
hi

if your date field data type is date/time then use this
$tdate = date('Y-m-d H:i:s',strtotime($tdate));

if data type is just date then use this
$tdate = date('Y-m-d',strtotime($tdate));


Title: Re: Datebox default date
Post by: wikusg on January 20, 2015, 03:15:00 AM
Hi, my problem is not on the php side. What happens is that I load the data from MySQL and it displays correct. Once I double click on the cell, it updates the date to todays date because it thinks the format is incorrect due to the fact that easyui expect the date in mm/dd/yyyy and is given yyyy-mm-dd. I'm still new to jquery and do not know how to change it to expect/change the date to a different format. I've tried the demo given in the documentation, but I do not understand exactly what they want me to do.

Regards,

Wikus


Title: Re: Datebox default date
Post by: thecyberzone on January 22, 2015, 02:38:24 AM
If you consider default format is mm-dd-yyyy in browser, and as in mysql contains yyyy-mm-dd format, during saving of date you have to change it in PHP as follows:
$td = $_REQUEST['trgdate'];
$trgdate = substr($td,6,4) . '-' . substr($td,0,2) . '-' . substr($td,3,2);

as well as during retrieval of the same you have change it again to mm-dd-yyyy format in PHP as follows:
$td = $row->trgdate;
$tdate = substr($td,5,2) . '-' . substr($td,8,2) . '-' . substr($td,0,4);

Hope this will solve your problem.


Title: Re: Datebox default date
Post by: thecyberzone on January 22, 2015, 02:52:19 AM
When editing a row, the editor's value depends on the corresponding field value. If the field value is empty or illegal, the datebox value will be set to the current day. Please confirm if the date field has a valid value. Of course, you can change the editor's value in 'onBeginEdit' event.
Code:
$('#dg').datagrid({
    onBeginEdit: function(index,row){
        var ed = $(this).datagrid('getEditor',{index:index,field:'datefield'});
        $(ed.target).datebox('setValue', '1/2/2014')
    }
});

Dear Mr. stworthy,

Is there any way to override the default date of the datebox, so that during empty or invalid date, datebox will remain empty, only if user selects a date from datebox it will be changed.