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. UiAutomator源码分析之UiAutomatorBridge框架

    上一篇文章<UIAutomator源码分析之启动和运行>我们描述了uitautomator从命令行运行到加载测试用例运行测试的整个流程,过程中我们也描述了UiAutomatorBridge ...

  2. 阐述linux IPC(五岁以下儿童):system V共享内存

    [版权声明:尊重原创.转载请保留源:blog.csdn.net/shallnet 要么 .../gentleliu,文章学习交流,不用于商业用途]         system V共享内存和posix ...

  3. 是男人就下100层【第四层】——Crazy贪吃蛇(1)

    贪吃蛇是一款非常经典的游戏,这些经典游戏给我们的童年添加了不少乐趣,今天開始我们来一步一步的在Android设备上实现一款贪吃蛇游戏,我也是第一次写这个游戏,有可能会写错,或者走弯路,可是终于希望能有 ...

  4. gtest框架

    解析gtest框架运行机制   1.前言 Google test是一款开源的白盒单元测试框架,据说目前在Google内部已在几千个项目中应用了基于该框架的白盒测试. 最近的工作是在搞一个基于gtest ...

  5. Visual Studio 2013进行单元测试

    使用Visual Studio 2013进行单元测试--初级篇   1.打开VS2013 --> 新建一个项目.这里我们默认创建一个控制台项目.取名为UnitTestDemo 2.在解决方案里面 ...

  6. HashMap之Hash碰撞冲突解决方案及未来改进

    说明:参考网上的两篇文章做了简单的总结,以备后查(http://blogread.cn/it/article/7191?f=wb  ,http://it.deepinmind.com/%E6%80%A ...

  7. 整理 W3CSchool 常用的CSS属性列表

    近期教学给学员总结常用的CSS属性,方便学习查询,正好发上来也给大家分享一下,O(∩_∩)O. 摘选自:http://www.w3cschool.com.cn/ 表格最右列的数字标识支持的CSS最低版 ...

  8. jquery 移动端轮播图

    <div class="slide"> <div class="slide-box"> <ul class="slide ...

  9. ios中mvc的FormsAuthentication.SetAuthCookie(cookieUserName, false)失败

    如果楼主使用.net开发,要注意FormsAuthentication.SetAuthCookie 方法的使用会导致ios出现该问题.因为这个方法在ios设备上是把票据加入到url中,导致url和你的 ...

  10. 回车tab切换

    //event表示事件对象,keyCode表示键值,srcElement事件源 function changeCommand(){ //如果按下的是回车,并且不是提交按钮,不是重置按钮,则回车认为是t ...