PDA

View Full Version : SetEditor of a grid column dynamically



sbodanapu
18 Jun 2012, 5:37 AM
Hi friend,
I am Ext-Js beginner and my functionality now is to dynamically change the combobox store used in the gridColumn Model based on the activity given in the combobox of the same row in the grid.

For instance,
if the activity is selected as 'Leave' , hours combobox should contain only values {' 4.5 hrs' , ' 9 hrs'}

else , hours combobox should contain all the decimal values of hours ranging from '0' to '9'

My code is given below...

sm: new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners : {
rowselect : {
fn : function(sm, index, record) {
if(record.data.project_activity=='Leave/Holiday'){
var cm = Ext.getCmp('effortgrid').getColumnModel();
var valCol = cm.getColumnById('eff_monday');
valCol.setEditor(LeaveEffortValue);
valCol = cm.getColumnById('eff_tuesday');
valCol.setEditor(LeaveEffortValue);
valCol = cm.getColumnById('eff_wednesday');
valCol.setEditor(LeaveEffortValue);
valCol = cm.getColumnById('eff_thursday');
valCol.setEditor(LeaveEffortValue);
valCol = cm.getColumnById('eff_friday');
valCol.setEditor(LeaveEffortValue);
valCol = cm.getColumnById('eff_saturday');
valCol.setEditor(LeaveEffortValue);
valCol = cm.getColumnById('eff_sunday');
valCol.setEditor(LeaveEffortValue);
console.log('project activity selected is '+record.data.project_activity);
}
else{
var cm = Ext.getCmp('effortgrid').getColumnModel();
var valCol = cm.getColumnById('eff_monday');
valCol.setEditor(selectEffortValue);
valCol = cm.getColumnById('eff_tuesday');
valCol.setEditor(selectEffortValue);
valCol = cm.getColumnById('eff_wednesday');
valCol.setEditor(selectEffortValue);
valCol = cm.getColumnById('eff_thursday');
valCol.setEditor(selectEffortValue);
valCol = cm.getColumnById('eff_friday');
valCol.setEditor(selectEffortValue);
valCol = cm.getColumnById('eff_saturday');
valCol.setEditor(selectEffortValue);
valCol = cm.getColumnById('eff_sunday');
valCol.setEditor(selectEffortValue);
}
}
}
}
})

I am getting the error as this.field is undefined when i change the row selections for two different project_activities..

FYI, the following are the editors i am using...

var selectEffortValue = new fm.ComboBox({
name: 'effort_monday',
id: 'effort_monday',
typeAhead: true,
triggerAction: 'all',
store:vlaueStore,
mode: 'local',
editable:false,
displayField: 'effortvalue',
valueField: 'effortvalue'
});

var LeaveEffortValue=new fm.ComboBox({
name: 'effort_leave',
id: 'effort_leave',
typeAhead: true,
triggerAction: 'all',
store:LeaveEffStore,
mode: 'local',
editable:false,
displayField: 'effortvalue',
valueField: 'effortvalue'
});

Am i correct in using the above mentioned logic?
Please help me with this soon..(:|(:|(:|

Thanks in Advance,
Sandeep

scottmartin
18 Jun 2012, 11:26 AM
Instead of performing all of this, why not just populate the store with different data:



if (condition) {
combo.store.loadData(data1)
} else {
combo.store.loadData(data2)
}


Scott.