Ext 行统计有意思的实现.(js对象的循环, ext列的设置)

时间:2021-08-27 16:51:40

考勤界面, 列包含日期. 行的数据格式:  需要实现 编辑一列然后在最后产生的统计的效果.

行数据内容.
Ext 行统计有意思的实现.(js对象的循环, ext列的设置)

Gird Load 的时候统计数据: 
-- 根据对象. 可以Ext.Date.parse 成功的都是日期列. 其他非日期列则不会执行统计.

function AttenAllStaticsCalc() {
for (var i = 0; i < AttendanceTable.store.data.items.length; i++) {
var record = AttendanceTable.store.data.items[i];
var recordData = record.data;
var staticQty = {};
for (var k in recordData) {
var tm = Ext.Date.parse(k, 'Ymd')
var recordDatas = recordData[k];
if (tm) {
if (recordData[k]) {
if (staticQty[recordData[k]] != undefined) {
staticQty[recordData[k]] += 1;
} else {
staticQty[recordData[k]] = 1;
}
}
}
} var res = "";
if (staticQty) {
for (var t in staticQty) {
if (staticQty[t]) {
var si = t + ": " + staticQty[t] + "; ";
res += si;
}
}
}
if (res.length > 0) {
res = res.substring(0, res.length - 2);
}
recordData['AttenStatics'] = res;
//record.set("AttenStatics", res); //显示数据
} AttendanceTable.view.refresh();
}

每行编辑后设置统计数字;

            var staticQty = {};
for (var k in recordData) {
var tm = Ext.Date.parse(k, 'Ymd')
var recordDatas = recordData[k];
if (tm) {
if (recordData[k]) {
if (staticQty[recordData[k]] != undefined) {
staticQty[recordData[k]] += 1;
} else {
staticQty[recordData[k]] = 1;
}
}
}
} //oldValue, newValue -1 + 1动作
staticQty[oldValue] = staticQty[oldValue] - 1;
staticQty[newValue] = typeof(staticQty[newValue]) == 'undefined' ? 1 : staticQty[newValue] + 1; var res = "";
if (staticQty) {
for (var t in staticQty) {
if (staticQty[t]) {
var si = t + ": " + staticQty[t] + "; ";
res += si;
}
}
}
if (res.length > 0) {
res = res.substring(0, res.length - 2);
} record.set("AttenStatics", res); //显示数据

使用