ext.datagrid.js

来自「anewssystem新闻发布系统集成使用了spring hibernate f」· JavaScript 代码 · 共 678 行 · 第 1/2 页

JS
678
字号
        var A = this.grid ? this.grid : this, B = A.selModel.getSelected(), D = "";
        if(B) {
            D = B.data[C];
        }
        return D;
    }, refresh : function() {
        var A = this.row.pageNo * this.pageSize - this.pageSize, B;
        this.setRowId("");
        if(this.params == null) {
            B = {params:{start:A, limit:this.pageSize}};
        } else {
            B = {params:{start:A, limit:this.pageSize, params:this.params}};
        }
        this.dataModel._options = B;
        this.dataModel.load();
        if(this.editor) {
            this.newRecordCount = 0;
            this.dataModel.commitChanges();
        }
    }, progress : function(B, D, A) {
        var C = Ext.get(D);
        if(B) {
            C.radioClass("active-msg");
            this.yesBtn.disable();
            this.noBtn.disable();
        } else {
            if(A == undefined || A) {
                this.dlg.hide();
                this.setValueofEmpty(this.getRowId() == "");
                this.refresh();
            }
            C.removeClass("active-msg");
            this.yesBtn.enable();
            this.noBtn.enable();
        }
    }, getChecked : function() {
        var E = this.dataSource.getCount(), D = new Array();
        if(E == 0) {
            return null;
        }
        for(var B = 0; B < E; B++) {
            var A = this.dataSource.getAt(B), C = $(this.id + "_checkbox_" + B);
            if(C.checked) {
                D[D.length] = A;
            }
        }
        return D.length == 1 ? D[0] : D;
    }, onRowClick : function(A, G) {
        if(!this.colClick) {
            return;
        }
        var C = $(this.gridDiv + "_checkbox_" + G), F = $(this.gridDiv + "_mycheckbox_" + G), D = $(this.gridDiv + "_label_" + G), E = this.checkList;
        getId(C, F, D, $(this.rowid));
        if(C.checked) {
            E[E.length] = G;
        } else {
            for(var B = 0; B < E.length; B++) {
                if(E[B] == G) {
                    E[B] = "X";
                    var H = E.toString().replace(/\,X/g, "").replace(/\X,/g, "");
                    E = H.split(",");
                    this.checkList = E;
                    E.sort(function(B, A) {
                        return B * 1 > A * 1 ? -1 : 1;
                    });
                    G = E[0];
                    if(G == "X") {
                        G = -1;
                    } else {
                        H = A.selModel.selectRow;
                        if(H) {
                            A.selModel.selectRow(G);
                        } else {
                            A.selModel.select(G, 0, false, true);
                        }
                    }
                    break;
                }
            }
        }
        if(G >- 1) {
            G = G * 1;
            if(G > this.pageSize) {
                G = G / 10;
            }
            this.setValue(G);
        } else {
            this.setValue();
        }
        this.colClick = false;
        if(!this.dlg) {
            this.createDialog();
        }
    }, getToolBarEvent : function() {
        var A = function(A) {
            this.obj.showDlg(A);
        };
        return A;
    }, link : function(D, H, C, G, B, F) {
        var I = F.obj.gridDiv + "_" + H.cellId;
        if(D.indexOf(".gif") >= 0) {
            D = "<image src=\"" + path + "/widgets/extjs/1.1/resources/images/aero/user/tree/" + D + "\">";
        }
        var E = "datagrids[{1}].colClick=true;datagrids[{1}].view(this)";
        var A = "<span style='cursor:pointer;color=#5285C5' id='{0}' onclick='" + E + "'>{2}</span>";
        A = String.format(A, I, F.obj.datagrids, D, G);
        return A;
    }, date : function(C, F, B, E, A, D) {
        var G = (C == "") ? "" : String.format(C.split(" ")[0].replace("-", "{0}").replace("-", "{1}"), "年","月") + "日";
        return G;
    }, integer : function(C, F, B, E, A, D) {
        if(C.indexOf(".") >= 0) {
            C = C.substring(0, C.indexOf("."));
        }
        return C;
    }, separator : function(C, F, B, E, A, D) {
        if(C.indexOf("@") >= 0) {
            return C.split("@")[1];
        }
        if(C.indexOf("|") < 0) {
            return C;
        }
        return C.split("|")[1];
    }, setCheckBox : function (D, H, C, G, B, F) {
        if(!D || D == "") {
            return"";
        }
/*
        F.obj.row = objectEval(D);
        var E = (F.obj.getRowId().indexOf(F.obj.row.id) >= 0);
        var A = "<div style='display:none'><input type=checkbox id='{0}_checkbox_{1}' {2} value=\"{3}\" ></div>";
        A += "<div id='{0}_mycheckbox_{1}' class='{4}' onclick='datagrids[{7}].colClick = true'></div>";
        A += "<label id='{0}_label_{1}' onclick='datagrids[{7}].colClick = true' class='{5}'>{6}.</label>";
        A = String.format(A, F.obj.gridDiv, G, E ? "checked" : "", F.obj.row.id, E ? "checkboxAreaChecked" : "checkboxArea", E ? "chosen" : "", F.obj.row.no, F.obj.datagrids);
*/
        var E = false;
        var A = "<div style='display:none'><input type=checkbox id='{0}_checkbox_{1}' {2} value=\"{3}\" ></div>";
        A += "<div id='{0}_mycheckbox_{1}' class='{4}' onclick='datagrids[{7}].colClick = true'></div>";
        A += "<label id='{0}_label_{1}' onclick='datagrids[{7}].colClick = true' class='{5}'>{6}.</label>";
        A = String.format(A, F.obj.gridDiv, G, E ? "checked" : "", D, E ? "checkboxAreaChecked" : "checkboxArea", E ? "chosen" : "", D, F.obj.datagrids);
        return A;
    }, setHeader : function(h) {
        var tagsArray, dataIndex;
        if(!h[0].dataIndex) {
            tagsArray = "";
            var tags = function(A) {
                tagsArray = A;
            };
            DWREngine.setAsync(false);
            this.exec.getTags(tags);
            DWREngine.setAsync(true);
        }
        var header = [{
            header    : "序号",
            dataIndex : "id",
            width     : 55,
            align     : "left",
            hidden    : false,
            sortable  : false,
            renderer  : this.setCheckBox
        }], fields = [{
            name:"id", mapping:"id"
        }];
        for(var i = 0; i < h.length; i++) {
            var renderer = h[i].renderer;
            //console.error(h[i].type);
            var align = "left";
            var hidden = false;
            var draw = h[i].draw != undefined ? h[i].draw : true;
            if(h[i].type != undefined) {
                renderer = eval("this." + h[i].type);
            }
            if(h[i].separator != undefined) {
                renderer = this.separator;
            }
            if(h[i].align != undefined) {
                align = h[i].align;
            }
            if(h[i].hidden != undefined) {
                hidden = h[i].hidden;
            }
            dataIndex = tagsArray ? tagsArray[i + 1] : h[i].dataIndex;
            h[i] = {
                header:h[i].header, dataIndex:dataIndex, width:h[i].width, align:align, hidden:hidden, sortable:h[i].sortable, renderer:renderer, draw:draw, id:dataIndex
            };
            if(this.editor) {
                h[i] = this.getEditor(h[i], dataIndex, i == 0);
            }
            fields = fields.concat([{
                name:dataIndex, mapping:dataIndex
            }]);
        }
        this.header = header.concat(h);
        this.fields = fields;
        var row_input = document.createElement("input");
        row_input.id = this.rowid;
        row_input.type = "hidden";
        document.body.appendChild(row_input);
        datagrids._obj = this;
        this.datagrids = datagrids.length;
        datagrids[this.datagrids] = this;
    }, getParams : function(H) {
        if(H != undefined) {
            var E = new Array(), G = new Array(), K = new Array(), I = "<separator>";
            for(var F = 0; F < H.length; F++) {
                var M = H[F], B = " ? ", L = M.pName, C = M.pMore, A = M.pValue, D  = M.pType, J = C == "like";
                L = L.replace(/\+/g, "||");
                A = J ? "%" + A + "%" : A;
                if(L.indexOf(")") >= 0 && L.indexOf("(") < 0) {
                    L = L.replace(")", "");
                    B = " ?) ";
                }
                if(C == "in") {
                    L = "instr(" + A + "|" + L + ")";
                    C = ">";
                    A = 0;
                    D = "Integer";
                }
                E[E.length] = L + " " + C + B + (M.pLogic == undefined ? "" : M.pLogic);
                if(A.length == 0) {
                    A = "null";
                }
                G[G.length] = A;
                K[K.length] = D;
            }
            H = E.toString().replace(/\,/g, " ").replace("|", ",");
            H += I + G.toString();
            H += I + K.toString();
        } else {
            H = null;
        }
        return H;
    }, addListener : function(B,A) {
        this.grid.addListener(B, A);
    }, getView : function() {
        return this.grid.getView();
    }, render : function(A, C) {
        this.params = this.getParams(A);
        if(!this.colModel) {
            this.row = {
                "pageNo":1
            };
            this.colModel = new Ext.grid.ColumnModel(this.header);
            var B = {
                root:"root", record:"rows", totalRecords:"TotalCount"
            };

    var recordType = Ext.data.Record.create([
        {name: "id",      mapping: "id",      type: "int"},
        {name: "image",   mapping: "image",   type: "string"},
        {name: "name",    mapping: "name",    type: "string"},
        {name: "forward", mapping: "forward", type: "string"},
        {name: "theSort", mapping: "theSort", type: "int"}
    ]);
            this.dataModel = new Ext.data.Store({
                proxy: new Ext.data.DWRProxy(MenuHelper.pagedQuery, true),
                reader: new Ext.data.ListRangeReader({
                    totalProperty: 'totalCount',
                    id: 'id'
                }, recordType),
                // 远端排序开关
                remoteSort: true,
                obj:this
/*
                proxy:new Ext.data.HttpProxy({
                    url:this.url
                }),
                reader:new Ext.data.XmlReader(B, this.fields),
                remoteSort:true,
                obj:this
*/
            });
            if(this.defaultSort) {
                this.colModel.defaultSortable = true;
                this.dataModel.setDefaultSort(this.defaultSort.field, this.defaultSort.dir);
            }
        }
        if(!this.grid) {
            this.grid = new Ext.grid.Grid(this.gridDiv, {
                ds:this.dataModel,
                colModel:this.colModel,
                enableColLock:false,
                loadMask:true
            });
            this.grid.addListener("rowclick", function(A) {
                A.isSelected = false;
            });
            this.grid.addListener("rowclick", this.onRowClick, this, true);

            //var rz = new Ext.Resizable("resize-grid", {
            //    wrap:true,
            //    minHeight:500,
            //    pinned:true,
            //    handles: 's'
            //});
            //rz.on('resize', this.grid.autoSize, this.grid);
            this.grid.render();
            this.setPagingBar();
            this.grid.getSelectedId = this.getSelectedId;
            this.grid.getChecked = this.getChecked;
            this.grid.getSelectedColValueByName = this.getSelectedColValueByName;
        }
        if(C != false) {
            this.pagingToolbar.loading.show();
            this.refresh();
        }
    }, getHeaderPanel : function() {
        this.headPanel = this.grid.getView().getHeaderPanel(true);
        return this.headPanel;
    }, getGridToolbar : function() {
        return new Ext.Toolbar(this.getHeaderPanel());
    }, setPagingBar : function(){
        var A = "显示&nbsp;{0}&nbsp;-&nbsp;{1}&nbsp;,&nbsp;共&nbsp;{2}&nbsp;条", C = "显示&nbsp;0&nbsp;-&nbsp;0&nbsp;,&nbsp;共&nbsp;0&nbsp;条";
        if(this.pageInfo == false) {
            A = "共&nbsp;{2}&nbsp;条";
            C = "共&nbsp;0&nbsp;条";
        }
        var B = this.grid.getView().getFooterPanel(this.paging);
        this.pagingToolbar = new Ext.PagingToolbar(B, this.dataModel, {
            pageSize:this.pageSize, displayInfo:true, displayMsg:A, emptyMsg:C
        });
        this.pagingToolbar.loading.hide();
        if(this.editor) {
            this.pagingToolbar.loading.on("click", function() {
                this.newRecordCount = 0;
                this.dataModel.commitChanges();
            } .createDelegate(this));
        }
    }, insertIntoPagingBar : function(A) {
        this.pagingToolbar.add("-", {
            pressed:(A.pressed ? A.pressed : false),
            enableToggle:(A.enableToggle ? A.enableToggle : false),
            text:A.text,
            cls:(A.cls ? A.cls : "detail"),
            toggleHandler:A.handler.createDelegate(this)
        });
    }
})

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?