Ext 行統計有意思的實現.(js對象的循環, ext列的設置)

考勤界面, 列包含日期. 行的數據格式:  須要實現 編輯一列而後在最後產生的統計的效果.

行數據內容.


Gird Load 的時候統計數據: 
-- 根據對象. 能夠Ext.Date.parse 成功的都是日期列. 其餘非日期列則不會執行統計.javascript

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();    
}

每行編輯後設置統計數字; java

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); //顯示數據

使用code

相關文章
相關標籤/搜索