Ext JS4百强应用: 用grid.plugin.CellEditing做高级查询 --第10强
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强的更多相关文章
- Ext JS4百强应用: 做可编辑的,可checked的treegrid--第11强
做一个可编辑的,可checked的treegrid,代码相当简洁: 请看代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN&quo ...
- EXT的bug 布局border 和 grid的cellediting
首先 我要的布局是上下两块,并且高度和按自己的喜欢可调节,所以我采用的是border的布局, 上下两块,都放grid列表,上面一块不可编辑,下面这块可编辑,如图 在编辑第二块的时候会出现这个现象 图一 ...
- Ext JS4百强应用:设置textfield的悬浮提示信息 --第8强
在Extjs4中有时候我们需要textfield的提示信息,但是我们发现textfield并没有这样的配置项. 这时候我们就要另想方法:我们需要在鼠标悬停在textfield组件的时候进行信息的提示, ...
- Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法
Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法 昨天在开发的时候遇到个小问题,就是如何将Grid的内容与Form一起发送到服务器端.默认情况下,表单(F ...
- Ext.grid.plugin.RowExpander的简单用法
有时候,我们在grid里渲染数据时,由于某些字段的内容太长,而grid又不会自动出现滚动条,于是溢出的内容后面就会出现省略号, 导致信息展示不完全.如果,这个信息不太重要,展示不完全也无关紧要.可是, ...
- 2013年度IT博客大赛跻身10强
2013年12月26日,由51CTO独家举办的2013年度IT博客大赛圆满落幕,荣幸跻身10强[http://fellow.51cto.com/art/201312/425528.htm],首先感谢各 ...
- 摹客项目在2018年工信部"创客中国"名列10强并荣获二等奖
2018“创客中国”互联网+大数据创新创业大赛(暨2018创客中国产业投资峰会)8月19日在厦门进行了总决赛.大赛由国家工业和信息化部.厦门市人民政府主办,厦门文广集团等承办.工信部信息中心领导.厦门 ...
- Ext Js 6.2.1 classic grid 滚动条bug解决方案
此bug未在其他版本发现,参考高版本代码重写类解决此bug,直接上代码: /** * 如果列表同时存在横向滚动条和竖向滚动条,当竖向滚动条滚动到底部时 * 点击横向滚动条,滚动条会自动滚动到顶部 * ...
- 名词解释——Ext JS4
Ext.onReady——Ext主入口,和onload事件不同,不需要页面所有东西加在出来. Ext js 的基本语法就是使用树状图来配置对象来定义界面: { config_options1:valu ...
随机推荐
- linux通过建模工具Umbrello
https://umbrello.kde.org/ Umbrello UML Modeller is a Unified Modelling Language (UML) diagram progra ...
- HDOJ 4416 Good Article Good sentence
题解转自:http://blog.csdn.net/dyx404514/article/details/8807440 2012杭州网络赛的一道题,后缀数组后缀自己主动机都行吧. 题目大意:给一个字符 ...
- 二叉树(8)----第一个二叉树K层节点和二进制部分K叶节点层,递归和非递归
1.二进制定义 typedef struct BTreeNodeElement_t_ { void *data; } BTreeNodeElement_t; typedef struct BTreeN ...
- php学习之路:php在iconv功能 详细解释
iconv函数库可以完毕各种字符集间的转换,是php编程中必不可少的基础函数库. 使用方法例如以下: $string = "亲爱的朋友欢迎訪问胡文芳的博客.希望给您带来一点点的帮助!&quo ...
- 让你的ubuntu串口程序可以直接读写串口
默认的情况下,如果我们使用一般用户去打开串口的话会出现 open failed 的错误 这个时候你可以在执行打开串口时加一个sudo,但每次这么需要这么干实在是太麻烦了. 这有一个方法可以跳过以超级用 ...
- C++中的左值和右值
左值和右值的定义 在C++中,能够放到赋值操作符=左边的是左值,能够放到赋值操作符右边的是右值.有些变量既能够当左值又能够当右值.进一步来讲,左值为Lvalue,事实上L代表Location,表示在内 ...
- avalonJS入门(一)
前端神器avalonJS入门(一) posted @ 2014-10-31 17:44 vajoy 阅读(1665) 评论(32) 编辑 收藏 avalonJS是司徒正美开发和维护的前端mvvm框 ...
- 使用Visual Studio 2010 - 初学者系列 - 学习者系列文章
本文介绍Visual Studio 2010的基本使用. 1. 欢迎界面 2. 进入界面 3.选择菜单中的项目 4.选择项目路径,还有空白解决方案 5.选择 新建解决方案文件夹 6.选择新建项目 ...
- Java设置环境变量
客上转过来的. 非常多人写了非常久java代码.还不知道环境变量是怎么一回事.科普一下. 一.java设置环境变量 - 精简版 1.右键打开我的电脑->属性->高级->环境变量 ...
- parent和top
function show(){ //parent是获取本窗口的父窗口 //window.parent.location.href="http://www.baidu.com" ...