Search 在列中搜索,在extjs4中使用网格
我正在尝试对我刚制作的网格进行搜索。我试过了,但速度太慢了。因此,我正在尝试构建一个不同的搜索,我在我正在使用的应用程序中的一些旧网格示例中确实有。下面的代码取自我的示例,它使用:Search 在列中搜索,在extjs4中使用网格,search,filter,grid,extjs4.1,Search,Filter,Grid,Extjs4.1,我正在尝试对我刚制作的网格进行搜索。我试过了,但速度太慢了。因此,我正在尝试构建一个不同的搜索,我在我正在使用的应用程序中的一些旧网格示例中确实有。下面的代码取自我的示例,它使用: fieldlabel:'Search', 将搜索放在tbar中,并按列筛选研究结果 // search { xtype : 'combo', enableKeyEvents : true, fieldLabel : 'Search', hideTrigger : true, typeAhead : fals
fieldlabel:'Search',
将搜索放在tbar中,并按列筛选研究结果
// search
{
xtype : 'combo',
enableKeyEvents : true,
fieldLabel : 'Search',
hideTrigger : true,
typeAhead : false,
editable : true,
listeners : {
'specialkey' : function(field, e) {
// pressing enter
if (e.keyCode == 13) {
if (field.lastValue != null|| field.lastValue != undefined) {
// if the search key isn't empty
var search = field.lastValue;
// remove old filter
if (store.isFiltered())
store.clearFilter(true);
// apply filter on fields selected
if (checked[0] == 1) {
if (checked[1] == 1)
if (checked[2] == 1)
store.filter([{
property : "admantN",
value : search,
anyMatch : true
}],
[{
property : "admant",
value : search,
anyMatch : true
}],
[{
property : "userN",
value : search,
anyMatch : true
}]);
else
store.filter([{
property : "admantN",
value : search,
anyMatch : true
}],
[{
property : "admant",
value : search,
anyMatch : true
}]);
else {
if (checked[2] == 1)
store.filter([{
property : "admantN",
value : search,
anyMatch : true
}],
[{
property : "userN",
value : search,
anyMatch : true
}]);
else
store.filter([{
property : "admantN",
value : search,
anyMatch : true
}]);
}
}
else {
if (checked[1] == 1)
if (checked[2] == 1)
store.filter([{
property : "userN",
value : search,
anyMatch : true
}],[{
property : "admant",
value : search,
anyMatch : true
}]);
else
store.filter([{
property : "admant",
value : search,
anyMatch : true
}]);
else
if (checked[2] == 1)
store.filter([{
property : "userN",
value : search,
anyMatch : true
}]);
}
search = "";
}
else {// if search key is blank remove old filters
if (store.isFiltered()) {
store.clearFilter();
}
}}}}// end listeners
},
// to select in which field search
{
xtype : 'checkboxgroup',
store : checked,
columns : 3,
vertical : false,
width : 250,
items : [
{
// Default searching field
boxLabel : 'Name',
checked : true
},
{boxLabel : 'Admant'},
{boxLabel : 'Username'}
],
listeners :
{
'change' :
// store checked field
function(th, newValue, oldValue) {
var ics = th.items.items;
for (i = 0; i < 3; i++) {
checked[i] = ics[i].checked;
}
}
}
},
// Refresh button
{
xtype : 'button',
text : 'Refresh',
icon : 'images/refresh.gif',
handler :
function() {
metodoA = "list";
// remove pending filters
if (store.isFiltered())
store.clearFilter(true);
// refresh data from the server
Ext.Ajax.request({
method : "GET",
url : ur + "admants?MetodoAD="+ metodoA + "&DBad=" + dbA,
timeout : 10000,
success :
function(response) {
var obj = null;
try {
obj = Ext.decode(response.responseText);
}
catch (error) {}
if (obj) {
store.loadData(obj);
}
else {
console.log('Invalid response');
}
},
failure :
function(response) {
alert("Refreshing request failed");
}
});}}]
// end toolbar's item
},// end tbar
//搜索
{
xtype:'组合',
enableKeyEvents:true,
fieldLabel:“搜索”,
希德崔格:没错,
typeAhead:false,
是的,
听众:{
“specialkey”:函数(字段,e){
//按回车键
如果(e.keyCode==13){
if(field.lastValue!=null | | field.lastValue!=未定义){
//如果搜索键不是空的
var search=field.lastValue;
//拆下旧滤清器
if(store.isFiltered())
store.clearFilter(true);
//对所选字段应用过滤器
如果(选中[0]==1){
如果(选中[1]==1)
如果(选中[2]==1)
存储过滤器([{
属性:“admantN”,
值:搜索,
任何匹配:正确
}],
[{
属性:“admant”,
值:搜索,
任何匹配:正确
}],
[{
属性:“userN”,
值:搜索,
任何匹配:正确
}]);
其他的
存储过滤器([{
属性:“admantN”,
值:搜索,
任何匹配:正确
}],
[{
属性:“admant”,
值:搜索,
任何匹配:正确
}]);
否则{
如果(选中[2]==1)
存储过滤器([{
属性:“admantN”,
值:搜索,
任何匹配:正确
}],
[{
属性:“userN”,
值:搜索,
任何匹配:正确
}]);
其他的
存储过滤器([{
属性:“admantN”,
值:搜索,
任何匹配:正确
}]);
}
}
否则{
如果(选中[1]==1)
如果(选中[2]==1)
存储过滤器([{
属性:“userN”,
值:搜索,
任何匹配:正确
}],[{
属性:“admant”,
值:搜索,
任何匹配:正确
}]);
其他的
存储过滤器([{
属性:“admant”,
值:搜索,
任何匹配:正确
}]);
其他的
如果(选中[2]==1)
存储过滤器([{
属性:“userN”,
值:搜索,
任何匹配:正确
}]);
}
搜索“”;
}
else{//如果搜索键为空,请删除旧筛选器
if(store.isFiltered()){
store.clearFilter();
}
}}}}//终端侦听器
},
//选择要搜索的字段
{
xtype:“checkboxgroup”,
商店:检查过了,
栏目:3,
垂直:假,
宽度:250,
项目:[
{
//默认搜索字段
boxLabel:'名称',
核对:正确
},
{boxLabel:'Admant'},
{boxLabel:'用户名'}
],
听众:
{
“改变”:
//存储选中字段
函数(th、newValue、oldValue){
var ics=第项、第项、第项;
对于(i=0;i<3;i++){
checked[i]=ics[i]。选中;
}
}
}
},
//刷新按钮
{
xtype:'按钮',
文本:“刷新”,
图标:“images/refresh.gif”,
处理程序:
函数(){
metodoA=“列表”;
//删除挂起的筛选器
if(store.isFiltered())
store.clearFilter(true);
//从服务器刷新数据
Ext.Ajax.request({
方法:“获取”,
url:ur+“admants?MetodoAD=“+metodoA+”&DBad=“+dbA,
超时:10000,
成功:
功能(响应){
var obj=null;
试一试{
obj=Ext.decode(response.responseText);
}
捕获(错误){}
如果(obj){
存储加载数据(obj);
}
否则{
console.log(“无效响应”);
}
},
失败:
功能(响应){
警报(“刷新请求失败”);
}
});}}]
//结束工具栏的项目
},//结束tbar
复制此解决方案的唯一问题是,我找不到任何使用fieldlabel和tbar search定义搜索框的教程或手册,该搜索框只有在我按下enter按钮后才能工作,并且不是“实时搜索”
有人有任何提示吗?技巧很简单,要在没有livesearchgridpanel的情况下创建搜索,您必须在表中创建一个名为“combo”的项:
xtype: 'combo',
在问题中粘贴的代码中,您必须将“store”关键字的值更改为mach,并使用您自己的store关键字。这用于检索研究完成后要显示的数据。它是通过存储选项的筛选方法完成的
之后,您必须设置过滤器功能的参数,以设置存储中的参数。用户可以使用“已检查”存储区来决定在哪个基础上进行搜索。在您的示例中有一个包含三个参数的数组
将整个代码放在“ext.grid.Panel”调用中