Ext.ns('Ext.ux.grid');
// 新类MyColumnModel的构造函数
Ext.ux.grid.MyColumnModel = function(grid, store, column){
this.grid = grid;
this.store = store;
var gender = [
['0100','男'],
['0101','女']
];
var department = [
['0200','文学院'],
['0201','历史学院'],
['0202','信息管理学院'],
['0203','经济与管理学院'],
['0204','计算机学院'],
['0205','水利水电学院'],
['0206','信息管理学院'],
['0207','医学部']
];
var title = [
['0300','助教'],
['0301','讲师'],
['0302','副教授'],
['0303','教授']
];
var genderCombo = new Ext.form.ComboBox({
store : new Ext.data.SimpleStore({
fields : ['value','text'],
data : gender
}),
emptyText : '请输入',
mode : 'local',
triggerAction : 'all',
valueField : 'value',
displayField : 'text',
readOnly : true
});
var departmentCombo = new Ext.form.ComboBox({
store : new Ext.data.SimpleStore({
fields : ['value','text'],
data : department
}),
emptyText : '请输入',
mode : 'local',
triggerAction : 'all',
valueField : 'value',
displayField : 'text',
readOnly : true
});
var titleCombo = new Ext.form.ComboBox({
store : new Ext.data.SimpleStore({
fields : ['value','text'],
data : title
}),
emptyText : '请输入',
mode : 'local',
triggerAction : 'all',
valueField : 'value',
displayField : 'text',
readOnly : true
});
this.customEditors = {
'GENDER' : new Ext.grid.GridEditor(genderCombo),
'DEPARTMENT' : new Ext.grid.GridEditor(departmentCombo),
'TITLE' : new Ext.grid.GridEditor(titleCombo),
'AGE': new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, style:'text-align:left;'})),
'PAPER' : new Ext.grid.GridEditor(new Ext.form.NumberField({selectOnFocus:true, style:'text-align:left;'}))
};
Ext.ux.grid.MyColumnModel.superclass.constructor.call(this,column);
};
Ext.extend(Ext.ux.grid.MyColumnModel, Ext.grid.ColumnModel, {
// private
getCellEditor : function(colIndex, rowIndex){
var p = this.store.getAt(rowIndex);
n = p.data.attrName;
if(colIndex==4)//表达式的值 propertyValue所在的列
{
if(this.customEditors[n]){
return this.customEditors[n];
}else{
var ed = new Ext.grid.GridEditor(new Ext.form.TextField({selectOnFocus:true}));
return ed;
}
}
else
return this.config[colIndex].editor;
}
});
Ext.onReady(function(){
var attributeData = {
"operators" : {
'' : '请选择',
'>' : '大于',
'<' : '小于',
'>=' : '大于或等于',
'<=' : '小于或等于',
'==' : '等于',
'!=' : '不等于'
},
"properties" : {
'' : '请选择',
'AGE' : '年龄',
'GENDER' : '性别',
'PAPERNUMBER' : '论文数量',
'TITLE' : '职称',
'DEPARTMENT' : '院系'
},
"values" : {
'0100':'男',
'0101':'女',
'0200':'文学院',
'0201':'历史学院',
'0202':'信息管理学院',
'0203':'经济与管理学院',
'0204':'计算机学院',
'0205':'水利水电学院',
'0206':'信息管理学院',
'0207':'医学部',
'0300':'助教',
'0301':'讲师',
'0302':'副教授',
'0303':'教授'
}
};
var comboData1 = [
['AGE' , '年龄'],
['GENDER' , '性别'],
['PAPERNUMBER' , '论文数量'],
['TITLE' , '职称'],
['DEPARTMENT' , '院系']
];
var comboData2 = [
['>','大于'],
['<','小于'],
['>=','大于或等于'],
['<=','小于或等于'],
['==','等于'],
['!=','不等于']
];
var combo1 = new Ext.form.ComboBox({
id : 'attrCombo',
store : new Ext.data.SimpleStore({
fields : ['value','text'],
data : comboData1
}),
emptyText : '请选择',
mode : 'local',
triggerAction : 'all',
valueField : 'value',
displayField : 'text',
readOnly : true
});
var combo2 = new Ext.form.ComboBox({
id : 'operatorCombo',
store : new Ext.data.SimpleStore({
fields : ['value','text'],
data : comboData2
}),
emptyText : '请选择',
mode : 'local',
triggerAction : 'all',
valueField : 'value',
displayField : 'text',
readOnly : true
});
var conditiondata = [];
var gStore = new Ext.data.SimpleStore({
fields: [
{name: 'fundConditionId'},
{name: 'attrName'},
{name: 'operator'},
{name: 'propertyValue'}
],
data : conditiondata
});
var sm = new Ext.grid.CheckboxSelectionModel({handleMouseDown: Ext.emptyFn});
var column = [
sm,
{
header : '条件id',
dataIndex : 'fundConditionId',
hidden : true
},{
header : '属性名称',
dataIndex : 'attrName',
editor : new Ext.grid.GridEditor(combo1),
renderer : attributeRenderer.createDelegate(this, ["properties"] , 0)
},{
header : '操作符',
dataIndex : 'operator',
editor : new Ext.grid.GridEditor(combo2),
renderer : attributeRenderer.createDelegate(this, ["operators"] , 0)
},{
header : '属性值',
dataIndex : 'propertyValue',
editor : new Ext.grid.GridEditor(new Ext.form.TextField({selectOnFocus:true})),
renderer : attributeRenderer.createDelegate(this, ["values"] , 0)
}
];
var PropertyRecord = Ext.data.Record.create([
{name: 'fundConditionId', type: 'string'},
{name : 'attrName', type : 'string'},
{name : 'operator', type : 'string'},
{name : 'propertyValue',type : 'string'}
]);
var fundConditionGrid = new Ext.grid.EditorGridPanel({
name : 'fundCondition',
id : 'fundCondition',
store : gStore,
cm : new Ext.ux.grid.MyColumnModel(this,gStore,column),
sm : sm,
tbar : new Ext.Toolbar(['-',{
text : '添加条件',
handler : _onAddCondition.createDelegate(this)
}, '-', {
text : '删除条件',
handler : _onRemoveCondition.createDelegate(this)
}, '-']),
frame:true,
collapsible: true,
animCollapse: false,
title : '助研基金申请条件',
width: 350,
height : 300,
iconCls: 'icon-grid',
clicksToEdit : 1,
renderTo: 'example1'
});
function attributeRenderer(attribute , val){
if(attributeData[attribute] && attributeData[attribute][val]) {
return attributeData[attribute][val];
} else
return val;
};
function _onAddCondition(){
var p = new PropertyRecord({
fundConditionId : "Condition"+ new Date().getTime(),
expressionId : "Exp"+ new Date().getTime(),
attrName : '',
operator : '',
propertyValue : '请输入属性值'
});
fundConditionGrid .stopEditing();
fundConditionGrid .getStore().insert(0,p);
fundConditionGrid .startEditing(0,0);
};
function _onRemoveCondition(){
var result = confirm( '确定要删除选中的条件吗?');
if(result){
var selections = fundConditionGrid.getSelectionModel().getSelections();
for (var i=0; i<selections.length; i++){
var record = selections[i];
fundConditionGrid.getStore().remove(record);
}
}
};
});
ext--example_code.zip_ext java_extjs_extjs example
版权申诉
117 浏览量
2022-09-24
03:48:34
上传
评论
收藏 11KB ZIP 举报
局外狗
- 粉丝: 64
- 资源: 1万+