EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: niketa.patel on July 01, 2018, 11:49:43 PM



Title: Initialise datebox
Post by: niketa.patel on July 01, 2018, 11:49:43 PM
Hi,

I would like to initialize databox in Editable datagrid.

I have a grid with two datebox  - startDate and endDate. When I click on datebox then calendar is initialised with current date.
If I select start date as 15-Jul-2015 [which is not current date] then I need to initialise endDate calendar to July 2015 rather than current date.

Can you please help me with this!

Thanks!


Title: Re: Initialise datebox
Post by: jarry on July 02, 2018, 01:51:23 AM
When begin to edit a row, call the 'getEditor' method to get these two datebox editor and bind an events on the first one, listen to some conditions and set the value for the second one. Please refer to the code below:
 
Code:
$('#dg').datagrid({
  onBeginEdit: function(index,row){
    var db1 = $(this).datagrid('getEditor', {index:index,field:'datebox1'});
    var db2 = $(this).datagrid('getEditor', {index:index,field:'datebox2'});
    $(db1.target).datebox({
      onChange: function(value){
        $(db2.target).datebox('setValue', ...)
      }
    })
  }
})


Title: Re: Initialise datebox
Post by: niketa.patel on July 03, 2018, 10:55:57 PM
Thank you for your response!

I did this way as I dont want to set value to second/end datebox

Code:
$('#dg').datagrid({
  onBeginEdit: function(index,row){
var db1 = $(this).datagrid('getEditor', {index:index,field:'datebox1'});
var db2 = $(this).datagrid('getEditor', {index:index,field:'datebox2'});
$(db2.target).textbox('textbox').bind('focus',function(e){

var db1Date = $.fn.datebox.defaults.parser($(db1.target).datebox('getValue'));
if(undefined != $.trim(db1Date) && $.trim(db1Date) != ''){
$(db2.target).datebox('calendar').calendar('moveTo', new Date(db1Date));
}
});
  }
})

Thanks!