ここで私のグリッド名は「rightpanel」です。レコードの各セルに入力された値を追加し、レコードの最後のセル/列に合計を表示しようとしています。しかし、私は以下に示すようにログインでの総労力を計算する際に問題に直面しています。これを達成するための他の方法はありますか?
ここでは、セルにTime(たとえば、-> 2.03)を挿入しています。ありがとうございます。それでは、お元気で
var selectionModel = new Ext.selection.CheckboxModel();
var fm=Ext.form;
var currentRecord;
var oldValue;//used to store old effort while re-editing the already entered cell
Ext.define('AM.view.rightpanel' ,{
extend:'Ext.grid.Panel',
alias : 'widget.rightpanel',
selModel : selectionModel,
store : 'addtaskstore',
id : 'rightpanel',
columnLines : true,
width:724,
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
pluginId:'rightPanelEditor'
})
],
このリスナーは、各セルのクリックをリッスンし、ロジックをサポートするためにそのセルの古い値をキャプチャするために使用されます
listeners:{
cellclick:function(thisObj, td, cellIndex, record, tr, rowIndex, e, eOpts)
{
var dataIndex = thisObj.getHeaderCt().getHeaderAtIndex(cellIndex).dataIndex;
if(eval(record.get(dataIndex))< 12) //changes made after main logic
{
oldValue = record.get(dataIndex);
}
currentRecord = record;
}
},
title:'TIMESHEET',
columns: [
{
header: 'Tasks',
dataIndex: 'task_name',
width: 160
},
{
header: 'Project Name',
dataIndex: 'project_name',
width: 160
},
{
dataIndex: 'monday',
width: 95,
id:'monday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
dataIndex: 'tuesday',
width: 95,
id:'tuesday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
dataIndex: 'wednesday',
width: 95,
id:'wednesday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
dataIndex: 'thursday',
width: 95,
id:'thursday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
dataIndex: 'friday',
width: 95,
id:'friday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
dataIndex: 'saturday',
width: 95,
id:'saturday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
dataIndex: 'sunday',
width: 95,
id:'sunday',
editor:{
xtype:'textfield',
listeners:{
'blur':function(o, t, h){
if(validateEffort(o)){
calculateTotal(o.value);
}
}
}
}
},
{
header: 'Total Efforts',
dataIndex: 'total_efforts',
width: 95,
editor:{
xtype:'textfield',
disabled:true
}
}
],
initComponent: function() {
this.callParent(arguments);
}
});
この関数は、セルクリック時にセルに入力された数値形式(2.34など)を検証するために使用されます
function validateEffort(obj){
var regEx=/(^([0-9]|[0-1][0-9]|[2][0-3]).([0-5][0-9])$)|(^([0-9]|[1][0-2])$)/;
if(obj && !regEx.test(obj.value)){
alert("Invalid value");
obj.setValue(oldValue);
return false;
}
return true;
}
この関数は、dataIndex:'total_efforts'を使用して列に表示される合計作業量(時間内)を計算するために使用されます。
function calculateTotal(newValue){
//alert("old = "+oldValue + " new = " +newValue);
oldValue = oldValue?oldValue:0.00;
if(currentRecord && oldValue !=newValue){
var currTotal = currentRecord.get('total_efforts');
//alert("currTotal=="+currTotal);
if(!currTotal || currTotal == 'NaN'){
currTotal = 0.00;
}
currentRecord.set('total_efforts',((eval(currTotal)+eval(newValue)-eval(oldValue))).toFixed(2));
var newcurrTotal = currentRecord.get('total_efforts');
var arr = [];
arr=newcurrTotal.split(".");
//alert("arr[1]--> " +arr[1]);
//alert(newcurrTotal);
if(eval(arr[1])>=60)
{
var q =parseInt(eval(arr[1])/60);
//alert("q --> "+parseInt(q));
var r = (eval(arr[1])%60)/100;
//alert("r --> "+r);
var newtotal = eval(newcurrTotal)+eval(q)-(eval(arr[1])/100)+r;
alert("new---> "+newtotal.toFixed(2));
//currentRecord.set('total_efforts',newtotal.toFixed(2));
}
//alert("new total=="+currentRecord.get('total_efforts'));
}
}