根据类型动态editor

来自ling
跳转至: 导航搜索
window.refreshcols = function() {
	var cols = view.id("dataSet7").getData();
	var dataType5 = view.id("dataSet5").getDataType();
	var grid = view.id("dataGridtestcol");	
	var gridtemplate=view.id("dataGridtestcoltemplate");
	dataType5.disableListeners();	
	grid.disableListeners();
	grid.removeAllColumns();
	dataType5.removeAllPropertyDef();
	//追加选择列
	var select=grid.addColumn(gridtemplate.getColumn("select"));
	select.set("readOnly",false);
	//追加序号列
	grid.addColumn(gridtemplate.getColumn("rownum"));
	cols.each(function(item) {
		var name = item.get("name");
		var dataType=item.get("type");
		var trigger=null;
		var editorType=null;
		if(dataType=="Date"){
			trigger="autoDateDropDown";
		}else if("Boolean"==dataType){
			editorType="CheckBox";
		}else if("String"==dataType){
			editorType="TextArea";
		}
		// var def=new dorado.PropertyDef(name);
		// def.set("label",name);
		if(dataType!=null)
		dataType5.addPropertyDef({
			name : name,
			label : name,
			dataType:dataType
		});
		grid.addColumn({
			property : name,
			trigger:trigger,
			editorType:editorType
		});
	});
	grid.addColumn({
		name:"ops",
		caption : "可用操作",
		width : 60,
		listener : {
			onRenderCell : function(self, arg) {
				$(arg.dom).empty();
				var button = new dorado.widget.Button({
					caption : "复制本行",
					renderTo : arg.dom,
					style : "margin: 0 2px",
					onClick : function() {
						copyCurrent();
					}
				});
			}
		}
	});
	dataType5.enableListeners();	
	grid.enableListeners();
}