ux.form.field.SearchField 列表、树形菜单查询扩展
//支持bind绑定store
//列表搜索扩展,支持本地查询
//支持树形菜单本地一级菜单查询
Ext.define('ux.form.field.SearchField', {
extend: 'Ext.form.field.Text',
alias: 'widget.uxSearchfield',
defaultBindProperty: 'store',
mixins: ['Ext.util.StoreHolder'],
triggers: {
clear: {
weight: 0,
cls: Ext.baseCSSPrefix + 'form-clear-trigger',
hidden: true,
//清除搜索条件
handler: 'clearValue',
scope: 'this'
},
search: {
weight: 1,
cls: Ext.baseCSSPrefix + 'form-search-trigger',
//查询
handler: 'onSearchClick',
scope: 'this'
}
},
//查询参数
paramName: 'query',
//是否本地查询
isLocal: false,
initComponent: function () {
var me = this,
store = me.store;
me.on({
//添加监听,监听回车键
specialkey: function (f, e) {
if (e.getKey() == e.ENTER) {
me.onSearchClick();
}
},
//监听内容改变
//在这里监听是为了实现多个搜索控件绑定同一个store时
//界面能够同步
change: function (t, value) {
var clear = t.getTrigger('clear');
//根据查询条件是否存在,显示隐藏小按钮
if (value.length > 0) {
if (clear.hidden) {
clear.show();
t.updateLayout();
}
} else {
clear.hide();
t.updateLayout();
me.onClearClick();
}
}
});
//如果strong是string类型,寻找对应的store
if (Ext.isString(store)) {
store = me.store = Ext.data.StoreManager.lookup(store);
}
//动态绑定store
me.bindStore(store || 'ext-empty-store', true);
me.callParent(arguments);
},
//清除value
clearValue: function () {
this.setValue('');
},
//清除过滤
onClearClick: function () {
//console.log('清除过滤');
var me = this,
activeFilter = me.activeFilter;
if (activeFilter) {
me.store.getFilters().remove(activeFilter);
me.activeFilter = null;
} else {
me.store.clearFilter(false);
}
},
//本地过滤
localFilter: function (value) {
var store = this.store,
paramName = this.paramName; //first clear any current filters on the store. If there is a new value, then suppress the refresh event
store.clearFilter(!!value);
//check if a value is set first, as if it isnt we dont have to do anything
//the user could have entered spaces, so we must split them so we can loop through them all
var searches = value.split(','),
regexps = [],
i, regex; //loop them all
for (i = 0; i < searches.length; i++) {
//if it is nothing, continue
if (!searches[i]) continue; regex = searches[i].trim();
regex = regex.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); //if found, create a new regular expression which is case insenstive
regexps.push(new RegExp(regex.trim(), 'i'));
} //now filter the store by passing a method
//the passed method will be called for each record in the store
store.filter(function (record) {
//树形菜单只过滤第一层
if (record.get('depth') > 1) {
return true;
}
var matched = []; //loop through each of the regular expressions
for (i = 0; i < regexps.length; i++) {
var search = regexps[i],
didMatch = search.test(record.get(paramName)); //if it matched the first or last name, push it into the matches array
matched.push(didMatch);
} return (regexps.length && matched.indexOf(true) !== -1);
});
},
//过滤
onSearchClick: function () {
var me = this,
value = me.getValue(),
store,
proxy;
if (value.length > 0) {
//本地还是远程过滤
if (!me.isLocal) {
store = me.store;
store.setRemoteFilter(true);
// 设置代理,设置过滤参数
proxy = store.getProxy();
proxy.setFilterParam(me.paramName);
proxy.encodeFilters = function (filters) {
return filters[0].getValue();
}
// Param name is ignored here since we use custom encoding in the proxy.
// id is used by the Store to replace any previous filter
me.activeFilter = new Ext.util.Filter({
property: me.paramName,
value: value
});
me.store.getFilters().add(me.activeFilter);
} else {
me.localFilter(value);
}
}
},
onDestroy: function () {
//清除过滤条件
var me = this,
store = me.store;
if (store) {
me.onClearClick();
me.store = null;
//移除绑定
me.bindStore(null);
}
me.callParent();
}
});
简单示例
Ext.define('类名', {
extend: 'Ext.tree.Panel',
title: '小区',
rootVisible : false,
store: '数据源,可bind绑定',
header: {
items: [{
//本地查询
isLocal:true,
xtype: 'uxSearchfield',
//
store: '数据源,可bind绑定',
//
paramName: '查询字段',
emptyText: '请输入关键词'
}]
}
});
ux.form.field.SearchField 列表、树形菜单查询扩展的更多相关文章
- ux.form.field.KindEditor 所见所得编辑器
注意需要引入KindEditor相关资源 //所见所得编辑器 Ext.define('ux.form.field.KindEditor', { extend: 'Ext.form.field.Text ...
- ux.form.field.Verify 验证码控件
//验证码控件 Ext.define('ux.form.field.Verify', { extend: 'Ext.container.Container', alias: ['widget.fiel ...
- ux.form.field.TreePicker 扩展,修复火狐不能展开bug
/** * A Picker field that contains a tree panel on its popup, enabling selection of tree nodes. * 动态 ...
- ux.form.field.Year 只能选年的时间扩展
效果如图,亲测6.2.1版本可用,用法同时间选择控件 //只选择年的控件 Ext.define('ux.picker.Year', { extend: 'Ext.Component', alias: ...
- ux.form.field.Month 只能选年、月的时间扩展
效果如图,亲测6.2.1版本可用,用法同时间选择控件 //月弹窗扩展 //只选月 Ext.define('ux.picker.Month', { extend: 'Ext.picker.Month', ...
- ux.form.field.Password 密码与非密码状态切换
效果如图: 扩展源码: //扩展 //密码按钮扩展 //支持在密码与非密码之间切换 Ext.define('ux.form.field.Password', { extend: 'Ext.form.f ...
- ux.form.field.GridDate 支持快速选择日期的日期控件
效果如图,亲测6.2.1版本可用 /** *支持快速选择日期的日期控件 */ Ext.define('ux.form.field.GridDate', { extend: 'Ext.form.fiel ...
- 在Bootstrap开发框架中使用bootstrapTable表格插件和jstree树形列表插件时候,对树列表条件和查询条件的处理
在我Boostrap框架中,很多地方需要使用bootstrapTable表格插件和jstree树形列表插件来共同构建一个比较常见的查询界面,bootstrapTable表格插件主要用来实现数据的分页和 ...
- 如何快速开发树形列表和分页查询整合的WInform程序界面
我在做Winform界面的时候,一般都是统一化处理,界面顶部放置一些字段条件供查询,下面就是分页查询列表,展示相关的数据.但有时候碰到一些表字段内容分类比较多,有一些特别重要,如果放在一个树形列表来进 ...
随机推荐
- WEB项目后端跨域请求
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- MongoDB中的字段类型Id
众所周知,在向MongoDB的集合中添加一条记录时,系统会自动增加一个字段名为"_id",类型为ObjectId的字段,其值为24位字符串,可以使用此值作为记录的唯一标识. 项目中 ...
- [WinAPI] API 8 [获取磁盘空间信息]
获取磁盘分区的总容量和空闲空间的容量可以使用GetDiskFreeSpace函数或GetDiskFree SpaceEx函数.GetDiskFreeSpace使用DWORD类型作为输出参数,由于DWO ...
- [BTS] BizTalk With EF
System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' ...
- nosql/nodejs基础
nosql定义:nosql--no only sql 目前流行的非关系型数据库:mongodb,redis,cassandra 非关系型数据库和内存存储hashmap数据结构有什么区别?hashmap ...
- paip.java 调用c++ dll so总结
paip.java 调用c++ dll so总结 ///////JNA (这个ms sun 的) 我目前正做着一个相关的项目,说白了JNA就是JNI的替代品,以前用JNI需要编译一层中间库,现在JNA ...
- D. Book of Evil
D. Book of Evil time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- O2O已死?不!美团点评们迎来新风口
当年的千团大战,巅峰时期曾涌入了5000多家团购网站,刘旷本人也参与了此次团购大战.而就在当时很多人都唱衰团购的时候,美团和大众点评却最终脱颖而出,市值一路飙升,人人网旗下的糯米网因为卖给了百度,也得 ...
- JAVA学习绘图颜色及其笔画属性设置字体显示文字
package com.graphics; import java.awt.*; import java.awt.geom.Rectangle2D; import java.util.Date; im ...
- node.js cluster多进程、负载均衡和平滑重启
1 cluster多进程 cluster经过好几代的发展,现在已经比较好使了.利用cluster,可以自动完成子进程worker分配request的事情,就不再需要自己写代码在master进程中rob ...