EasyUI Forum
April 29, 2024, 06:59:45 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Datebox default date  (Read 17219 times)
wikusg
Newbie
*
Posts: 3


View Profile
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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')
    }
});
Logged
wikusg
Newbie
*
Posts: 3


View Profile
« Reply #2 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
Logged
ehussain
Newbie
*
Posts: 16


View Profile Email
« Reply #3 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));
Logged
wikusg
Newbie
*
Posts: 3


View Profile
« Reply #4 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
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #5 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.
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #6 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!