1 //支持bind绑定store
  2 //列表搜索扩展,支持本地查询
  3 //支持树形菜单本地一级菜单查询
  4 Ext.define('ux.form.field.SearchField', {
  5     extend: 'Ext.form.field.Text',
  6     alias: 'widget.uxSearchfield',
  7     defaultBindProperty: 'store',
  8     mixins: ['Ext.util.StoreHolder'],
  9     triggers: {
 10         clear: {
 11             weight: 0,
 12             cls: Ext.baseCSSPrefix + 'form-clear-trigger',
 13             hidden: true,
 14             //清除搜索条件
 15             handler: 'clearValue',
 16             scope: 'this'
 17         },
 18         search: {
 19             weight: 1,
 20             cls: Ext.baseCSSPrefix + 'form-search-trigger',
 21             //查询
 22             handler: 'onSearchClick',
 23             scope: 'this'
 24         }
 25     },
 26     //查询参数
 27     paramName: 'query',
 28     //是否本地查询
 29     isLocal: false,
 30     initComponent: function () {
 31         var me = this,
 32         store = me.store;
 33         me.on({
 34             //添加监听,监听回车键
 35             specialkey: function (f, e) {
 36                 if (e.getKey() == e.ENTER) {
 37                     me.onSearchClick();
 38                 }
 39             },
 40             //监听内容改变
 41             //在这里监听是为了实现多个搜索控件绑定同一个store时
 42             //界面能够同步
 43             change: function (t, value) {
 44                 var clear = t.getTrigger('clear');
 45                 //根据查询条件是否存在,显示隐藏小按钮
 46                 if (value.length > 0) {
 47                     if (clear.hidden) {
 48                         clear.show();
 49                         t.updateLayout();
 50                     }
 51                 } else {
 52                     clear.hide();
 53                     t.updateLayout();
 54                     me.onClearClick();
 55                 }
 56             }
 57         });
 58         //如果strong是string类型,寻找对应的store
 59         if (Ext.isString(store)) {
 60             store = me.store = Ext.data.StoreManager.lookup(store);
 61         }
 62         //动态绑定store
 63         me.bindStore(store || 'ext-empty-store', true);
 64         me.callParent(arguments);
 65     },
 66     //清除value
 67     clearValue: function () {
 68         this.setValue('');
 69     },
 70     //清除过滤
 71     onClearClick: function () {
 72         //console.log('清除过滤');
 73         var me = this,
 74         activeFilter = me.activeFilter;
 75         if (activeFilter) {
 76             me.store.getFilters().remove(activeFilter);
 77             me.activeFilter = null;
 78         } else {
 79             me.store.clearFilter(false);
 80         }
 81     },
 82     //本地过滤
 83     localFilter: function (value) {
 84         var store = this.store,
 85             paramName = this.paramName;
 86
 87         //first clear any current filters on the store. If there is a new value, then suppress the refresh event
 88         store.clearFilter(!!value);
 89         //check if a value is set first, as if it isnt we dont have to do anything
 90         //the user could have entered spaces, so we must split them so we can loop through them all
 91         var searches = value.split(','),
 92             regexps = [],
 93             i, regex;
 94
 95         //loop them all
 96         for (i = 0; i < searches.length; i++) {
 97             //if it is nothing, continue
 98             if (!searches[i]) continue;
 99
100             regex = searches[i].trim();
101             regex = regex.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
102
103             //if found, create a new regular expression which is case insenstive
104             regexps.push(new RegExp(regex.trim(), 'i'));
105         }
106
107         //now filter the store by passing a method
108         //the passed method will be called for each record in the store
109         store.filter(function (record) {
110             //树形菜单只过滤第一层
111             if (record.get('depth') > 1) {
112                 return true;
113             }
114             var matched = [];
115
116             //loop through each of the regular expressions
117             for (i = 0; i < regexps.length; i++) {
118                 var search = regexps[i],
119                     didMatch = search.test(record.get(paramName));
120
121                 //if it matched the first or last name, push it into the matches array
122                 matched.push(didMatch);
123             }
124
125             return (regexps.length && matched.indexOf(true) !== -1);
126         });
127     },
128     //过滤
129     onSearchClick: function () {
130         var me = this,
131         value = me.getValue(),
132         store,
133         proxy;
134         if (value.length > 0) {
135             //本地还是远程过滤
136             if (!me.isLocal) {
137                 store = me.store;
138                 store.setRemoteFilter(true);
139                 // 设置代理,设置过滤参数
140                 proxy = store.getProxy();
141                 proxy.setFilterParam(me.paramName);
142                 proxy.encodeFilters = function (filters) {
143                     return filters[0].getValue();
144                 }
145                 // Param name is ignored here since we use custom encoding in the proxy.
146                 // id is used by the Store to replace any previous filter
147                 me.activeFilter = new Ext.util.Filter({
148                     property: me.paramName,
149                     value: value
150                 });
151                 me.store.getFilters().add(me.activeFilter);
152             } else {
153                 me.localFilter(value);
154             }
155         }
156     },
157     onDestroy: function () {
158         //清除过滤条件
159         var me = this,
160            store = me.store;
161         if (store) {
162             me.onClearClick();
163             me.store = null;
164             //移除绑定
165             me.bindStore(null);
166         }
167         me.callParent();
168     }
169 });

简单示例

 1 Ext.define('类名', {
 2     extend: 'Ext.tree.Panel',
 3     title: '小区',
 4     rootVisible : false,
 5     store: '数据源,可bind绑定',
 6     header: {
 7         items: [{
 8             //本地查询
 9             isLocal:true,
10             xtype: 'uxSearchfield',
11             //
12             store: '数据源,可bind绑定',
13             //
14             paramName: '查询字段',
15             emptyText: '请输入关键词'
16         }]
17     }
18 });

ux.form.field.SearchField 列表、树形菜单查询扩展相关推荐

  1. ux.form.field.Verify 验证码控件

    1 //验证码控件 2 Ext.define('ux.form.field.Verify', { 3 extend: 'Ext.container.Container', 4 alias: ['wid ...

  2. ux.form.field.Year 只能选年的时间扩展

    效果如图,亲测6.2.1版本可用,用法同时间选择控件 1 //只选择年的控件 2 Ext.define('ux.picker.Year', { 3 extend: 'Ext.Component', 4 ...

  3. java数据库动态树形菜单_bootstrap treeview树形菜单 动态扩展 连数据库

    二话不说,先来看效果图: 呃呃,虽然不是很美观......不过功能实现就好啦~ 数据库模型是这样的: 我做了什么工作呢? 简单解释一下,就是通过查数据库,把上面的数据查出来,每一行数据封装成为一个节点 ...

  4. layui树形菜单右键_layui树形菜单写的树形列表(treetable)

    基于layui v2.2.5的 layui-tree写了一个treetable(树形列表) 效果 1.1 收起效果图 1.2 展开效果图 1.开发预备 首先需要到layui官网https://www. ...

  5. Ext.ux.form.SearchField使用方法

    这学期一直在做一个管理系统,前台用到了ExtJs,现在开始总结这一学期的学习心得,首先我们从Ext.ux.form.SearchField开始讲,因为这个东西一直困扰我好长时间,直到项目结束前几天我才 ...

  6. ext中引用ux_Ext.ux.form.SearchField使用方法

    这学期一直在做一个管理系统,前台用到了ExtJs,现在开始总结这一学期的学习心得,首先我们从Ext.ux.form.SearchField开始讲,因为这个东西一直困扰我好长时间,直到项目结束前几天我才 ...

  7. 根据用户id查询菜单列表(菜单权限问题)

    根据用户id查询菜单列表(菜单权限问题): 最高级用户菜单效果图: 较低级别用户菜单效果图: SQL语句分析图: 根据用户id查询对应菜单(权限)SQL语句: SELECT * FROM user_r ...

  8. Struts2+Hibernate+Spring+ZTree+Dtree 实现树形菜单

    2019独角兽企业重金招聘Python工程师标准>>> 1.第一步配置web.xml <?xml version="1.0" encoding=" ...

  9. layui树形菜单右键_layui-treetable

    最新版本是基于layui v2.2.3, 附件中有layui v1.0.7 2018.4.28 Updated 添加了全选checkbox 另外demo.html删掉部分代码,以免监听事件冲突 201 ...

最新文章

  1. VSCode中.py文件找不到路径的解决办法
  2. css选择器 pa,p~a,p+a区别
  3. Zynq ZC702平台 QSPI + eMMC实现
  4. 消防信号总线原理_消防报警系统中消防模块分类与用途简介
  5. Nhibernate中session的状态与session.connection.state状态的差别的解释
  6. C++利用线性探查实现存储机制hash table的算法(附完整源码)
  7. 【转】000.DICOM:DICOM标准学习路线图(初稿)!!!!!!!!!!!!
  8. java调用sql返回list_Spring JdbcTemplate实现有java.sql.ResultSet结果集返回的存储过程调用 | 学步园...
  9. DCL双检查锁机制实现线程安全的单例设计模式
  10. Java描述 数据结构与算法
  11. iOS 不通过改变url 与web JS 交互
  12. 专注企业市场 或是网盘危机的有效出路
  13. 【Spring】Service 注入失败,空指针
  14. 如何通过U盘等外部设备启动带有T2芯片的Mac?
  15. Linux加入Windows域
  16. java 清理页面缓存数据_清除浏览器缓存的几种方法总结(必看)
  17. 彻底理解 Window 和 WindowManager
  18. IJCAI2022论文合集(持续更新中)
  19. 谈谈一只菜鸟转行Erlang游戏服务端的经历(希望大佬指导,也希望我的经历能给一些还未毕业的同学或者正在迷茫自己工作内容的同学一些感触)
  20. Longest Commen Prefix

热门文章

  1. 电视看板实现原理_电脑显示器如何改装成电视机?详细改装方法,修电脑师傅告诉你...
  2. bzoj 刷题计划~_~
  3. MariaDB mysql 比较区别 选择
  4. BZOJ3675 [APIO2014]序列分割
  5. plsql 简单介绍
  6. mfc控件位置调整和坐标确定 .
  7. 【win32】vs2010的窗体程序Helloworld
  8. C# ProgressBar用法:模拟进度条
  9. Java—JVM加载机制
  10. stm32车牌识别_基于STM32单片机的车牌识别