我有一个显示grid
当我编辑一个字段(薪水)时,我想根据cost
的新编辑值更新其他列字段值,例如salary
。
因此,cost
将被计算为salary
除以否。开发人员(伯爵)
我试图这样做,但无法设定价值。
任何建议
以下是我的代码
_getSpan: function(val) {
return val;
},
_draw_grid: function(newHash, committedData) {
acceptedPoints = {};
Ext.Array.each(committedData, function(cData){
if ( ! acceptedPoints[cData.ProjectName] ) { acceptedPoints[cData.ProjectName] = 0; }
acceptedPoints[cData.ProjectName] = cData.Accept;
});
summaryHash = {};
_.each(projects, function(team) {
if (!summaryHash[team] && newHash[team]) {
summaryHash[team] = {
Name: team,
Count: newHash[team].length,
Days: 10,
Points: acceptedPoints[team],
Salary: "200,000",
Cost: 200000/newHash[team].length,
ManDays: 0
};
if (acceptedPoints[team] > 0) {
summaryHash[team].ManDays = (10/acceptedPoints[team]) * newHash[team].length;
}
};
});
records = [];
Ext.Object.each(summaryHash, function(key, value) {
if (newHash[key]) {
records.push(value);
}
});
this.records = records;
var cfgsValues = [];
var self = this;
cfgsValues.push({text: 'Teams', style:"background-color: #D2EBC8", dataIndex: 'Name', width: 170, renderer: function(value, meta_data, record, row, col) {
return value;
}});
cfgsValues.push({text: '# Developers', style:"background-color: #D2EBC8", dataIndex: 'Count', width: 70, renderer: function(value, meta_data, record, row, col) {
self.Count = value;
return value;
}});
cfgsValues.push({text: '# Points', style:"background-color: #D2EBC8", dataIndex: 'Points', width: 70, renderer: function(value, meta_data, record, row, col) {
return value;
}});
cfgsValues.push({text: '# Days in Sprint', style:"background-color: #D2EBC8", dataIndex: 'Days', width: 70, renderer: function(value, meta_data, record, row, col) {
return value;
}});
cfgsValues.push(
{text: '# Average Salary Cost per Sprint', style:"background-color: #D2EBC8", dataIndex: 'Salary', width: 100, renderer: function(value, meta_data, record, row, col) {
self.value = value;
return "$" +value;
},
editor: {
xtype: 'textfield', // this assumes that salary is a number; if not, set to 'textfield'
listeners: {
click: {
element: 'el', //bind to the underlying el property on the panel
fn: function(){
self.cost = self.value/self.Count;
console.log('click el', self.value, self);
self._getSpan(self.cost);
}
}
}
}
});
cfgsValues.push({text: '# Cost of 1 Story Point', style:"background-color: #D2EBC8", dataIndex: 'Cost', width: 100, renderer: function(value, meta_data, record, row, col) {
self.cost = value;
//return "$"+ Ext.Number.toFixed(value, 2);
return self._getSpan(record.raw.Cost);
}});
cfgsValues.push({text: '# man-days need per 1 Story Point', style:"background-color: #D2EBC8", dataIndex: 'ManDays', width: 100, renderer: function(value, meta_data, record, row, col) {
self.man_days = value;
return Ext.Number.toFixed(value, 2);
}});
this.setLoading(false);
self.add({
xtype: 'rallygrid',
bodyBorder: 1,
id: 'mychart',
showPagingToolbar: false,
showRowActionsColumn: false,
enableEditing:true,
editable: true,
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
store: Ext.create('Rally.data.custom.Store', {
data: records
}),
columnCfgs: cfgsValues
});
}
答案 0 :(得分:0)
嘿找到了这样做的方法
我只是将Cost
值0
保留在开头
summaryHash[team] = {
Name: team,
Count: newHash[team].length,
Days: 10,
Points: acceptedPoints[team],
Salary: "200000",
Cost: 0,
ManDays: 0
};
然后我的Salary
列可编辑
cfgsValues.push(
{text: '# Average Salary Cost per Sprint', style:"background-color: #D2EBC8", dataIndex: 'Salary', width: 100, renderer: function(value, meta_data, record, row, col) {
return "$" +value;
},
editor: {
xtype: 'textfield', // this assumes that salary is a number; if not, set to 'textfield'
}
});
现在每当我修改Salary
值时,它都会更改Cost
值
cfgsValues.push({text: '# Cost of 1 Story Point', style:"background-color: #D2EBC8", dataIndex: 'Cost', width: 100, renderer: function(value, meta_data, record, row, col) {
return Ext.Number.toFixed(record.get('Salary')/record.get('Count'), 2);
}});