I have defined onBeforeEdit of an editable datagrid as follows:
onBeforeEdit: function(index,row){
flag = 0;
alert("onBeforeEdit");
var colDate = $(this).datagrid('getColumnOption', 'trgdate');
var colRating = $(this).datagrid('getColumnOption', 'mrating_ass');
if(row.sktype == 'General') {
colRating.editor = null;
alert(row.sktype);
colDate.editor = {
type:'combobox',
options:{
method: 'get',
valueField:'trgdate',
textField:'trgdate',
panelHeight:135,
url: 'rating.getPlan.php?yr='+yr+'&trgcode='+row.trgcode,
onLoadSuccess: function(data){
if (data.length == 0) {
// alert(data.length);
flag = 1;
alert('G'+flag);
colDate.editor = 'datebox';
}
}
}
};
}
else {
colRating.editor = {
type:'combobox',
options:{
valueField:'mrating_ass',
textField:'mrating_ass',
data: [ {mrating_ass:'X', mrating_ass:'X'},
{mrating_ass:'Y', mrating_ass:'Y'},
{mrating_ass:'Z', mrating_ass:'Z'},
{mrating_ass:'NA', mrating_ass:'NA'}
],
panelHeight:90,
required:true
}
};
if (row.mrating_ass == 'Z'){
colDate.editor = {
type:'combobox',
options:{
method: 'get',
valueField:'trgdate',
textField:'trgdate',
panelHeight:135,
url: 'rating.getPlan.php?yr='+yr+'&trgcode='+row.trgcode,
onLoadSuccess: function(data){
if (data.length == 0) {
flag = 1;
alert('Z'+flag);
colDate.editor = 'datebox';
}
}
}
};
}
else {
colDate.editor = null;
}
}
alert(2+"-"+flag);
if (flag == 1) {
alert('Zero');
colDate.editor = null;
colDate.editor = {
type:'datebox'
};
}
},What is happening here, probably onLoadSuccess of colDate editor is firing with some delay, in above example, the firing sequence is as follows:
1. onBeforeEdit
2. then in If (row.sktype=='General') shows row.sktype -> General
3. Then it directly goes out of IF - ELSE and show 2 and Flag = 0
4. After it I don't know it shows G1 / Z1 in corresponding onLoadSuccess event.
So, I couldnot change the colDate editor from combobox to datebox as flag show 0, but it should be 1 when there is no data loaded in combobox editor.