87,910
社区成员
发帖
与我相关
我的任务
分享
Ext.ns('Ext.ux.grid');
Ext.ux.grid.MyColumnModel = function (grid, store, column) {
this.grid = grid;
this.store = store;
var gender = [['0100', '男'], ['0101', '女']];
var department = [['0200', '文学院'], ['0201', '医学院']];
var title = [['0300', '助教'], ['0301', '教授']];
var genderCombo = new Ext.form.ComboBox({
store: new Ext.data.ArrayStore({
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.ArrayStore({
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.ArrayStore({
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, {
getCellEditor: function (colIndex, rowIndex) {
var p = this.store.getAt(rowIndex);
n = p.data.attrName;
if (colIndex == 4) {
if (this.customEditors[n]) {
return this.customEditors[n];
} else {
var ed = new Ext.grid.GridEditor(new Ext.form.TextField({
selectOnFocus: true
}));
return ed;
}
}
return this.config[colIndex].editor;
}
});
Ext.onReady(function () {
var comboData1 = [['AGE', '年龄'], ['DEPARTMENT', '院系']];
var comboData2 = [['>', '大于'], ['!=', '不等于']];
var combo1 = new Ext.form.ComboBox({
id: 'attrCombo',
store: new Ext.data.ArrayStore({
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.ArrayStore({
fields: ['value', 'text'],
data: comboData2
}),
emptyText: '请选择',
mode: 'local',
triggerAction: 'all',
valueField: 'value',
displayField: 'text',
readOnly: true
});
var conditiondata = [];
var gStore = new Ext.data.ArrayStore({
fields: [
{ name: 'fundConditionId' },
{ name: 'attrName' },
{ name: 'operator' },
{ name: 'propertyValue' }
],
data: conditiondata
});
var rec = new Ext.data.Record({ attrName: 'AGE', operator: '>', propertyValue: '' });
gStore.add(rec);
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)
},
{
header: '操作符',
dataIndex: 'operator',
editor: new Ext.grid.GridEditor(combo2)
},
{
header: '属性值',
dataIndex: 'propertyValue',
editor: new Ext.grid.GridEditor(new Ext.form.TextField({ selectOnFocus: true }))
}];
var fundConditionGrid = new Ext.grid.EditorGridPanel({
name: 'fundCondition',
id: 'fundCondition',
store: gStore,
cm: new Ext.ux.grid.MyColumnModel(this, gStore, column),
sm: sm,
tbar: ['-', { text: '添加条件' }, '-', { text: '删除条件' }, '-'],
collapsible: true,
animCollapse: false,
title: '助研基金申请条件',
width: 350,
height: 300,
clicksToEdit: 1,
renderTo: 'ext'
});
});