Ext JS4,用grid.plugin.CellEditing做高级查询:

写了90%,界面出来了,小兴奋就贴出来,还有细节要调整,基本能用。

代码:

Ext.define('chenghao.admin.SearchGrid', {
extend: 'Ext.grid.Panel',
requires: [
'Ext.selection.*',
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.form.*'
],
initComponent: function() {
this.cellEditing = new Ext.grid.plugin.CellEditing({
clicksToEdit: 1
});
//可用查询项
var fieldStore = new Ext.data.Store({
fields: ['value', 'text'],
proxy: {
type: 'ajax',
url: CONF.CONN_URL,
extraParams: {
module: 'admin',
action: 'get_search_field_list'
},
reader: {
type: 'json',
root: CONF.JSON_READER_ROOT
}
},
folderSort: true,
autoLoad: false
});
// 比较运算符数据源
var bijiaoStore = new Ext.data.Store({
fields: ['value', 'text'],
proxy: {
type: 'ajax',
url: CONF.CONN_URL,
extraParams: {
module: 'admin',
action: 'get_search_operator_list'
},
reader: {
type: 'json',
root: CONF.JSON_READER_ROOT
}
},
folderSort: true,
autoLoad: false
});
// 逻辑运算符数据源
var luojiStore = new Ext.data.Store({
fields: ['value', 'text'],
proxy: {
type: 'ajax',
url: CONF.CONN_URL,
extraParams: {
module: 'admin',
action: 'get_search_operator_list',
key: 'logic_operator'
},
reader: {
type: 'json',
root: CONF.JSON_READER_ROOT
}
},
folderSort: true,
autoLoad: false
}); var me = this;
Ext.apply(this, {
title: '高级查询',
region: 'north',
//height: 120,
split: true, //自动伸展
collapsible: true, //可折叠 plugins: [me.cellEditing],
store: new Ext.data.Store({
fields: ['LeftParenthesis', 'QueryFieldNametext', 'QueryFieldName', 'QueryComparisonOperationtext', 'QueryComparisonOperation',
'QueryText', 'QueryValue', 'RightParenthesis', 'QueryLogicOperator', 'QueryLogicOperatortext'],
data: {
'search': [{
"LeftParenthesis": "",
"QueryFieldName": "",
"QueryComparisonOperation": "",
"QueryText": "",
"RightParenthesis": "",
"QueryLogicOperator": ""
}]
},
proxy: {
type: 'memory',
url: '',
reader: {
type: 'json',
root: 'search'
}
}
}),
selType: 'cellmodel', //设置为单元格选择模式
columns: [{
header: '删除',
//width: '5%',
sortable: false,
fixed: true,
align: 'center',
xtype: 'actioncolumn',
items: [{
//icon: DeleteIcon,
iconCls: 'icon-action icon-delete-record',
handler: function(grid, rowIndex, colIndex) {
//alert(grid.getStore().getCount());
var rec = grid.getStore().getAt(rowIndex);
if (grid.getStore().getCount() != 1) {
Ext.Msg.confirm('提示', '确定要删除吗?', function(btn) {
if (btn == 'yes') {
grid.getStore().remove(rec);
}
});
} else {
Ext.Msg.alert('错误提示','当前是最后一行,不能删除!');
}
}
}]
}, {
header: '左括号',
//width: '9%',
dataIndex: 'LeftParenthesis',
align: 'center',
field: {
xtype: 'combo',
store: new Ext.data.SimpleStore({
fields: ['value', 'text'],
data: [['1', '('], ['0', '无']]
}),
valueField: 'text',
displayField: 'text',
triggerAction: 'all', // 无论有没有内容,下拉列表全部显示,有内容会自动在该内容上高亮显示
selectOnFocus: true, // 用户不能自己输入,只能选择列表中有的记录
editable: false,
emptyText: "--请选择--"
}
}, {
header: '查询条件',
dataIndex: 'QueryFieldNametext',
//width: '23%',
align: 'center',
field: {
xtype: 'combobox',
hiddenname: 'value',
store: fieldStore,
valueField: 'text',
displayField: 'text',
triggerAction: 'all', // 无论有没有内容,下拉列表全部显示,有内容会自动在该内容上高亮显示
selectOnFocus: true, // 用户不能自己输入,只能选择列表中有的记录
editable: false,
emptyText: "--请选择--",
// 给查询条件加展开事件
listeners: {
expand: function() {
// 定义等待效果
if (this.value == "") {
fieldStore.load({
callback: function(records, options, success) {
}
});
}
},
change: function(e, value, oldValue) {
var index = fieldStore.find('text', e.getValue()); //me.getStore().getAt(0).data.QueryFieldName = "123";
var row = me.getSelectionModel().getCurrentPosition().row;
if (index != -1) {
fieldStore.each(function(rec) {
if (rec.get('text') == e.getValue()) {
//alert(rec.get('value'));
me.getStore().getAt(row).data.QueryFieldName = rec.get('value');
}
});
}
//alert(this.value);
//alert(Ext.JSON.encode(me.getSelectionModel().getCurrentPosition()));
}
}
}
}, {
header: '查询条件',
dataIndex: 'QueryFieldName',
align: 'center',
hideable: false,
hidden: true
}, {
header: '比较运算符',
dataIndex: 'QueryComparisonOperationtext',
//width: '10%',
align: 'center',
field: {
xtype: 'combobox',
hiddenname: 'value',
store: bijiaoStore,
valueField: 'text',
displayField: 'text',
triggerAction: 'all', // 无论有没有内容,下拉列表全部显示,有内容会自动在该内容上高亮显示
selectOnFocus: true, // 用户不能自己输入,只能选择列表中有的记录
editable: false,
emptyText: '',
listeners: {
change: function(e, value, oldValue) {
var index = bijiaoStore.find('text', e.getValue());
var row = me.getSelectionModel().getCurrentPosition().row;
if (index != -1) {
bijiaoStore.each(function(rec) {
if (rec.get('text') == e.getValue()) {
me.getStore().getAt(row).data.QueryComparisonOperation = rec.get('value');
}
});
}
}
}
}
}, {
header: '比较运算符',
dataIndex: 'QueryComparisonOperation',
align: 'center',
hideable: false,
hidden: true
}, {
header: '请输入查询条件',
dataIndex: 'QueryText',
width: 180,
align: 'center',
field:{
xtype: 'textfield',
listeners: {
click: function(e, h, rowIndex) {
var rec = me.getStore().getAt(rowIndex).data;
var fieldId = rec.QueryFieldNametext; if (fieldId == "") {
Ext.Msg.alert("请选择查询条件");
return;
}
if (rec.QueryComparisonOperation == "is null" || rec.QueryComparisonOperation == "is not null"){
return;
}
}
}
}
}, {
header: '右括号',
//width: '9.6%',
dataIndex: 'RightParenthesis',
align: 'center',
field: {
xtype: 'combo',
store: new Ext.data.SimpleStore({
fields: ['value', 'text'],
data: [['1', ')'], ['0', '无']]
}),
valueField: 'text',
displayField: 'text',
triggerAction: 'all', // 无论有没有内容,下拉列表全部显示,有内容会自动在该内容上高亮显示
selectOnFocus: true, // 用户不能自己输入,只能选择列表中有的记录
editable: false,
emptyText: "--请选择--"
}
}, {
header: '逻辑运算符',
dataIndex: 'QueryLogicOperatortext',
//width: '10%',
align: 'center',
field: {
xtype: 'combo',
hiddenname: 'value',
store: luojiStore,
valueField: 'text',
displayField: 'text',
triggerAction: 'all', // 无论有没有内容,下拉列表全部显示,有内容会自动在该内容上高亮显示
selectOnFocus: true, // 用户不能自己输入,只能选择列表中有的记录
editable: false,
emptyText: '',
listeners: {
change: function(e, value, oldValue) {
var index = luojiStore.find('text', e.getValue());
var row = me.getSelectionModel().getCurrentPosition().row;
if (index != -1) {
luojiStore.each(function(rec) {
if (rec.get('text') == e.getValue()) {
me.getStore().getAt(row).data.QueryLogicOperator = rec.get('value');
}
});
}
}
}
}
}, {
header: '逻辑运算符',
dataIndex: 'QueryLogicOperator',
align: 'center',
hideable: false,
hidden: true
}, {
header: '操作',
//width: '5%',
fixed: true,
align: 'center',
xtype: 'actioncolumn',
items: [{
//icon: AddIcon,
iconCls: 'add',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex).data;
if (rec.QueryFieldName == "") {
Ext.Msg.alert('错误提示','请输入查询条件!');
return;
} else if (rec.QueryComparisonOperation == "") {
Ext.Msg.alert('错误提示','请输入比较运算符!');
return;
} else if (rec.QueryLogicOperator == "") {
Ext.Msg.alert('错误提示','请输入逻辑运算符!');
return;
}
// 插入一行查询条件
me.getStore().insert(rowIndex + 1, '');
}
}] }],
dockedItems: [{
xtype: 'toolbar',
items: [{
//icon: SearchIcon,
text: '查询',
handler: function() {
var SearchStore = me.getStore();
var count = SearchStore.getCount(); if (count == 1 && SearchStore.getAt(0).data.QueryFieldName == "") {
//alert(SearchStore.getAt(0).data.QueryFieldName); var LeftParenthesis = SearchStore.getAt(0).data.LeftParenthesis;
var RightParenthesis = SearchStore.getAt(0).data.RightParenthesis;
if (LeftParenthesis == "" && RightParenthesis != "") {
Ext.Msg.alert('错误提示', '括号不匹配,请修改查询条件!');
return;
}
if (LeftParenthesis != "" && RightParenthesis == "") {
Ext.Msg.alert('错误提示', '括号不匹配,请修改查询条件!');
return;
}
me.getStore();
return;
} for(var i = 0; i< count; i++){
var a = new Array();
alert(Ext.JSON.encode(me.getStore().getAt(i).data));
//alert(me.getStore().getAt(i).data.LeftParenthesis);
//record = grid.getStore().getAt(i);
//var colname = grid.getColumnModel().getDataIndex(i); //获取列名
//var celldata = grid.getStore().getAt(cell[0]).get(colname); //获取数据
//Ext.MessageBox.alert("test",colname);
//for (var j = 0; j < colIndex; colIndex++) {
//Ext.MessageBox.alert("test",grid.getColumnModel().getDataIndex(j));
//}
} //var msg = dynamicPublicSearch(SearchStore);
//if (msg == "") {
//me.getStore();
//}
}
}]
}]
}); this.callParent();
}
});

Ext JS4百强应用: 用grid.plugin.CellEditing做高级查询 --第10强的更多相关文章

  1. Ext JS4百强应用: 做可编辑的,可checked的treegrid--第11强

    做一个可编辑的,可checked的treegrid,代码相当简洁: 请看代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN&quo ...

  2. EXT的bug 布局border 和 grid的cellediting

    首先 我要的布局是上下两块,并且高度和按自己的喜欢可调节,所以我采用的是border的布局, 上下两块,都放grid列表,上面一块不可编辑,下面这块可编辑,如图 在编辑第二块的时候会出现这个现象 图一 ...

  3. Ext JS4百强应用:设置textfield的悬浮提示信息 --第8强

    在Extjs4中有时候我们需要textfield的提示信息,但是我们发现textfield并没有这样的配置项. 这时候我们就要另想方法:我们需要在鼠标悬停在textfield组件的时候进行信息的提示, ...

  4. Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法

    Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法 昨天在开发的时候遇到个小问题,就是如何将Grid的内容与Form一起发送到服务器端.默认情况下,表单(F ...

  5. Ext.grid.plugin.RowExpander的简单用法

    有时候,我们在grid里渲染数据时,由于某些字段的内容太长,而grid又不会自动出现滚动条,于是溢出的内容后面就会出现省略号, 导致信息展示不完全.如果,这个信息不太重要,展示不完全也无关紧要.可是, ...

  6. 2013年度IT博客大赛跻身10强

    2013年12月26日,由51CTO独家举办的2013年度IT博客大赛圆满落幕,荣幸跻身10强[http://fellow.51cto.com/art/201312/425528.htm],首先感谢各 ...

  7. 摹客项目在2018年工信部"创客中国"名列10强并荣获二等奖

    2018“创客中国”互联网+大数据创新创业大赛(暨2018创客中国产业投资峰会)8月19日在厦门进行了总决赛.大赛由国家工业和信息化部.厦门市人民政府主办,厦门文广集团等承办.工信部信息中心领导.厦门 ...

  8. Ext Js 6.2.1 classic grid 滚动条bug解决方案

    此bug未在其他版本发现,参考高版本代码重写类解决此bug,直接上代码: /** * 如果列表同时存在横向滚动条和竖向滚动条,当竖向滚动条滚动到底部时 * 点击横向滚动条,滚动条会自动滚动到顶部 * ...

  9. 名词解释——Ext JS4

    Ext.onReady——Ext主入口,和onload事件不同,不需要页面所有东西加在出来. Ext js 的基本语法就是使用树状图来配置对象来定义界面: { config_options1:valu ...

随机推荐

  1. C#实现Web文件上传的两种方法

    1. C#实现Web文件的上传 在Web编程中,我们常需要把一些本地文件上传到Web服务器上,上传后,用户可以通过浏览器方便地浏览这些文件,应用十分广泛. 那么使用C#如何实现文件上传的功能呢?下面笔 ...

  2. EasyMonkeyDevice vs MonkeyDevice&HierarchyViewer API Mapping Matrix

    1. 前言 本来这次文章的title是写成和前几篇类似的<EasyMonkeyDevice API实践全记录>,内容也打算把每个API的实践和建议给记录下来,但后来想了下觉得这样子并不是最 ...

  3. Monkey源码分析之事件注入

    本系列的上一篇文章<Monkey源码分析之事件源>中我们描述了monkey是怎么从事件源取得命令,然后将命令转换成事件放到事件队列里面的,但是到现在位置我们还没有了解monkey里面的事件 ...

  4. Codeforces Round #FF 446A DZY Loves Sequences

    预处理出每一个数字能够向后延伸多少,然后尝试将两段拼起来. C. DZY Loves Sequences time limit per test 1 second memory limit per t ...

  5. knob.js进度插件

    关于knob.js进度插件的使用 关于这个插件,妹的,第一次使用坑死爹了,各种不会,幸亏我有持之以恒的精神,最终还是让其臣服于我的胯下.... 1.  引入 head  部分添加knob.js,同时引 ...

  6. C#实现文档转换成PDF

    网上有很多将doc.ppt.xls等类型的文档转换成pdf的方法,目前了解到的有两大类: 1.使用虚拟打印机将doc.ppt.xls等类型的文档 2.使用OFFICE COM组件 我采用了第二种方法实 ...

  7. android 使用 service 实现音乐

    今天的球员趁service.播放音乐service结束,进度条activity结束,因此,基础工作activity和service互动,本文将使用IBinder互动.主要activity能够调用ser ...

  8. Byte[]、Image、Bitmap 之间的相互转换

    原文:Byte[].Image.Bitmap 之间的相互转换 /// <summary>        /// 将图片Image转换成Byte[]        /// </summ ...

  9. git简单教材

    0)初始化 $ git config --global user.name "xxx" $ git config --global user.email "xxx@gma ...

  10. .NET MVC4 实训记录之一(引入Unity3.0 Ioc框架)

    一直在做维护项目,没有机会接触完整的架构,于是自学.NET MVC.自今日起,将自学的过程.遇到的问题以及解决方案记录下来. 在WebApp项目中右键,使用NuGet引入Unity3.0.