日期:2014-05-16  浏览次数:20362 次

extjs项目整理二
girdpanel curd
/**
* viewConfig作用在grid's UI试图上的配置项对象, 任何Ext.grid.GridView可用的配置
*选项都可在这里指定。
* forceFit True表示为自动展开/缩小列的宽度以适应grid的宽度,这样就不会出现水
*平的滚动条。ColumnModel中任意的width的设置可覆盖此配置项。
**/
TabPanelGrid = Ext.extend(Ext.grid.GridPanel, {
	initComponent : function() {
		if(!this.csm){
			this.sm = new Ext.grid.CheckboxSelectionModel();
		}else{
			this.sm = this.csm;
		}
		//this.autoHeight = true;
		this.stripeRows = true;
		//this.border = false;
		this.viewConfig = {
			forceFit : true
		};
		this.createColumns();
		this.createBbar();
		this.createtbar();
		TabPanelGrid.superclass.initComponent.call(this);
	}
}		



CreateColumns

/**
* dataIndex(可选的)数据索引,相当于Grid记录集(Ext.data.Store里面的
* Ext.data.Record )*中字段名称,字段的值用于展示列里面的值(column's value)。*如不指定,Record*的数据列中的索引将作为列的索引。
**/
createColumns : function() {
		var cols = [];
		cols.push(this.sm);
		for ( var i = 0; i < this.cols.length; i++) {
			var f = this.cols[i];
			if(f.dataIndex)cols.push(f);
		}
		this.columns = cols;
	}


createBbar

	createBbar : function() {
		this.bbar = new Ext.PagingToolbar( {
			displayInfo : true,
			store : this.store
		});
	}



createTbar
createtbar : function() {
		this.tbar = new Ext.Toolbar( {
			items : [ "-", {
				text : '增加',
				handler : this.createRecord.createDelegate(this)
			}, "-", {
				text : '修改',
				handler : this.updateRecord.createDelegate(this)
			}, "-", {
				text : '删除',
				handler : this.removeRecord.createDelegate(this)
			}, "-", new Ext.ux.form.SearchField( {
				store : this.store,
				width : 150
			}) ]
		});
	}



createRecord

/**
*this.cols 是全局cols(初始化时的那个cols)
*cols 是函数里面声明的cols
**/
createRecord : function() {
		this.showWindow();
		form = this.getForm();
		form.baseParams = {
			create : true
		};
		//表单置空
		var emptyRecord = {};
		for ( var i = 0; i < this.cols.length; i++) {
				var f = this.cols[i].dataIndex;
				emptyRecord[f] = '';
		}
		form.setValues(emptyRecord);
	}


updateRecord
	updateRecord : function() {
		var r = this.getSelectedRecord();
		if (r != false) {
			this.showWindow();
			this.form = this.getForm();
			this.form.baseParams = {create : false};
			this.form.loadRecord(r);
		}
	}



getSelectedRecord

/**
*getSelectionModel返回grid的RowSelectionModel
*getSelections() : Array 
*返回以选取的纪录。Returns the selected records 
*getSelected() : Record 
*返回选区中的第一个记录。
**/
getSelectedRecord : function() {
		var sm = this.getSelectionModel();
		if (sm.getCount() == 0) {
			Ext.Msg.alert('信息', '请选择记录!');
			return false;
		} else {
			return sm.getSelections()[0];
	}
	}



getForm
/**
*getForm() : ext.form.BasicForm
*返回该面板包含的Form
**/
getForm : function() {
		return this.getFormPanel().getForm();
}	



getFormPanel

getFormPanel : function() {
		if (!this.gridForm) {
			this.gridForm = this.createForm();
		}
		return this.gridForm;
	}	



CreateForm

/**
*this.cols 初始化得到
* trackResetOnLoad : Boolean 
*如果为true,则表单对象的form.reset()方法重置到最后一次加载的数据或*setValues()数据,以相对于一开始创建表单那时的数据。
**/
createForm : function() {
		var items = new Array();
		for ( var i = 0; i < th