간단한 Grid 패키지

4918 단어 ext
너무 복잡해서 간단한 봉투로 포장해야 한다
 
Ext.namespace("Ext.ux.yiminghe")
Ext.ux.yiminghe.JsonGridPanel = function (config) {

    var fieldsData = [];
    for (var i = 0; i < config.columns.length; i++) {
        fieldsData.push(config.columns[i].dataIndex);
    }
    //config.baseParams=config.baseParams||[];
    //config.baseParams.limit=config.pageSize;
    //config.baseParams.start=0;
    config.store = new Ext.data.JsonStore({
        url: config.dataSource, // url,
        root: 'rows',
        baseParams:config.baseParams,
        totalProperty:'results',        // 
        fields: fieldsData
    });
    
    config.store.lastOptions={params:{start:0,limit:config.pageSize}};

    var columns = [new Ext.grid.RowNumberer()];
    for (var i = 0; i < config.columns.length; i++) {
        if (config.columns[i].show)
            columns.push(config.columns[i]);
    }

    config.columns = columns;

    Ext.ux.yiminghe.JsonGridPanel.addMenuScope(config.tbar, this);
    config.store.on('loadexception', function(othis, options, response, e) {
				if(response.responseText.trim() !='')
        Ext.Msg.alert(' ', response.responseText);
        else
        	Ext.Msg.alert(' ',' ');
        return;
    });
    if (config.dynamicFunc)
        config.store.on('beforeload', function(store_, options) {
            config.dynamicFunc(options.params);
        });

    if (config.maskAll)
        config.loadMask = new Ext.LoadMask(Ext.getBody(), {msg:" ..."});
    else
        config.loadMask = true;

    config.bbar = new Ext.PagingToolbar({     // grid 
        pageSize:config.pageSize,                    // 
        store: config.store,           // grid 
        displayInfo:true ,
        items:config.pageBarItems,
        plugins:config.pageBarPlugins
    })//end bbar;
    Ext.apply(this, config);
  
    Ext.ux.yiminghe.JsonGridPanel.superclass.constructor.call(this,arguments);
  
    if (this.doubleClick) {
        this.on('rowdblclick', function(grid2, rowIndex, ee)
        {

            var store = grid2.getStore();
            var oRecord = store.getAt(rowIndex);
            this.doubleClick(oRecord);
            ee.stopEvent();

        }, this);
    }
    
    if (this.singleClick) {
        this.on('rowclick', function(grid2, rowIndex, ee)
        {

            var store = grid2.getStore();
            var oRecord = store.getAt(rowIndex);
            this.singleClick(oRecord);
            ee.stopEvent();

        }, this);
    }


    if (this.rowcontextmenu) {
       
        Ext.ux.yiminghe.JsonGridPanel.addMenuScope(this.rowcontextmenu, this);
        this.on('rowcontextmenu', function(grid2, rowIndex, ee)
        {

            if (!this.rowcontextmenu_) {
                this.rowcontextmenu_ = Ext.menu.MenuMgr.get({
                    id:'rowcontextmenu_-ctx',
                    items: this.rowcontextmenu
                });
            }
            this.getSelectionModel().selectRow(rowIndex);
            this.rowcontextmenu_.showAt(ee.getXY());
            ee.preventDefault();
        }, this);
    }

}


Ext.extend(Ext.ux.yiminghe.JsonGridPanel, Ext.grid.GridPanel, {
    getSelectionRecords:function() {
        if (this.getSelectionModel().getSelections()[0])
            return  this.getSelectionModel().getSelections();
        else {
            alert(' !');
          return false;
          }
    },
      reload:function() {
      	this.getStore().reload();
      }
    ,
    getSelectionRecord:function() {
        if (this.getSelectionModel().getSelections()[0])
            return  this.getSelectionModel().getSelections()[0];
        else {
            alert(' !');
          return false;
          }
    }

});

Ext.ux.yiminghe.JsonGridPanel.addMenuScope = function (obj, sco) {
    if (!obj)  return;
    if(obj.length)
	    for (var i = 0; i < obj.length; i++) {
	        if (!obj[i] || typeof obj[i] == 'string')    continue;
	        obj[i]['scope'] = sco;
	        if (obj[i].menu)
	            yiminghe.dynamicTable.addMenuScope(obj[i].menu, sco);
	    }
}
 

좋은 웹페이지 즐겨찾기