博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Extjs4实现客户端搜索(过滤数据)
阅读量:4501 次
发布时间:2019-06-08

本文共 4328 字,大约阅读时间需要 14 分钟。

首先看前端代码:

Ext.define('User', {
extend: 'Ext.data.Model', fields: [ {name: 'username', type: 'string'}, {name: 'sex', type: 'string'}, {name: 'age', type: 'int'}, {name: 'position', type: 'string'} ] }); var myStore = Ext.create('Ext.data.Store', {
model: 'User', proxy: {
type: 'ajax', url : 'data/get_users.php', api:{
read:'data/get_users.php', query:'data/users.json' }, reader: {
type: 'json', root: 'root' } }, autoLoad: true }); Ext.define('MyApp.view.ui.MyPanel', {
extend: 'Ext.panel.Panel', height: 364, width: 468, layout: {
align: 'stretch', type: 'vbox' }, title: '用户列表', initComponent: function() {
var me = this; me.items = [ {
xtype: 'form', bodyPadding: 10, title: '', flex: 1, items: [ {
xtype: 'textfield', fieldLabel: '关键词', labelAlign: 'right', labelWidth: 60, name:'key', id:'key', anchor: '100%' }, {
xtype: 'button', margin: '10 0 0 65', text: '查询', handler:function(btn){
var form=btn.up('form').getForm(); var key=form.getValues().key;//获取输入框的值 var pattern=new RegExp(key); Ext.getCmp('mygrid').getStore().filterBy(function(record,id){ var username=record.get('username'); return pattern.test(username);//检索每一列的username是否包含输入框的值 }); } } ] }, {
xtype: 'gridpanel', title: '', id:'mygrid', flex: 3, store:myStore, columns: [ {
xtype: 'gridcolumn', dataIndex: 'username', text: '用户名' }, {
xtype: 'gridcolumn', dataIndex: 'sex', text: '性别' }, {
xtype: 'gridcolumn', dataIndex: 'age', text: '年龄' }, {
xtype: 'gridcolumn', dataIndex: 'position', text: '职位' } ], viewConfig: {
}, dockedItems: [ {
xtype: 'toolbar', dock: 'top', items: [ {
xtype: 'button', text: '新增' }, {
xtype: 'button', text: '编辑选中' }, {
xtype: 'button', text: '删除选中' }, {
xtype: 'button', text: '刷新', handler:function(){
Ext.getCmp('mygrid').getStore().load(); } } ] } ], selModel: Ext.create('Ext.selection.CheckboxModel', {
}) } ]; me.callParent(arguments); } }); Ext.onReady(function(){
Ext.create('MyApp.view.ui.MyPanel',{
renderTo:Ext.getBody() }); });

下面是服务端的代码:

转载于:https://www.cnblogs.com/crazymus/archive/2012/03/30/2425484.html

你可能感兴趣的文章
Myslq 之修改数据库
查看>>
maven工程转为web工程时没有add web project capabilities选项的解决办法
查看>>
[BZOJ1192][HNOI2006]鬼谷子的钱袋
查看>>
正则表达式之 数据验证 与 文本替换
查看>>
CLR via C#:CLR的执行模型
查看>>
JS获取服务器时间
查看>>
如何对数据排序和拆分文件
查看>>
数据解析01-15
查看>>
linux 安装mysql数据库——yum安装法
查看>>
Several ports (8005, 80, 8009) required by Tomcat v6.0 Server at localhost are already in use
查看>>
事件监听器
查看>>
设计模式之单例设计模式
查看>>
异常的基本概念
查看>>
iOS 离屏渲染学习笔记
查看>>
iOS Xib布局某些控件显示或隐藏<约束的修改>
查看>>
苹果端手机微信页面长按图片无法保存的解决方案
查看>>
球的移动(move)
查看>>
页面禁止双击选中
查看>>
打印流
查看>>
TCP/IP模型的一个简单解释
查看>>