简体   繁体   English

ExtJS-使用RegEx过滤缓冲存储

[英]ExtJS - Filter buffered store with RegEx

I've a MYSQL server connected to a buffered store. 我有一个连接到缓冲存储的MYSQL服务器。 In some cases i must filter the records, the research must be case Insensitive , so I've used a regex to try checking the value in every case,because mysql server is case sensitive. 在某些情况下,我必须筛选记录,研究必须是不区分大小写的,所以我用一个正则表达式来尝试检查在任何情况下的价值,因为MySQL服务器是区分大小写的。 Here is the code of research bar: 这是研究栏的代码:

onSearchClick : function(){
        var me=this;
        if(me.getValue()!==''){
            var value=me.getValue();
            if(value.match(/ /g)){}else{
                value=value.split(""); //rome-> 'r''o''m''e'
                var valueApp='';
                Ext.Array.each(value, function(val) {
                    var m=val.toLowerCase();
                    var M=val.toUpperCase();
                    val='['+m+M+']';//also tryed with ()
                    valueApp=valueApp+val;
                });
                value=new RegExp(valueApp);
                console.log(value); //value=rome returns -> /[rR][oO][mM][eE]/
                me.store.filter{
                    property : me.paramName,
                    value    : value,
                    operator: '*=',
                    caseSensitive: false,
                    exactMatch: false,
                    anyMatch: true
                });
            }
            me.getTrigger('clear').show();
            me.updateLayout();
        }
    }

I can't match values, now all the values on the database are in uppercase, but probably they will change, so have you got a solution to this problem? 我无法匹配值,现在数据库上的所有值都是大写的,但可能它们会更改,所以您有解决此问题的方法吗? what is wrong in my code? 我的代码有什么问题?

Using a filter with ROME as filter value the records are filtered successfully, but using regex no way to make it work. 使用以ROME作为过滤器值的过滤器,可以成功过滤记录,但是使用正则表达式无法使其正常工作。

EXAMPLEs:



 store.filter(param,value); //tryed with almost all options 
    search rome -> records with rome
    search Rome -> records with Rome

search ROME -> records with ROME
search /[rR][oO][mM][eE]/ -> no records

I need to have Always all the records 我需要拥有所有记录

You have a multitude of issues and misunderstandings here. 您在这里有很多问题和误解。

A minor note: even if the SQL server is binary, you should be able to set a character set and collation on a table. 一个小小的注意事项:即使SQL Server是二进制的,您也应该能够在表上设置字符集和排序规则。

But the main thing is that you are mixing client-side filtering, server-side filtering, and a buffered store. 但是最主要的是,您要混合客户端过滤,服务器过滤和缓冲存储。

Client-side filtering can only filter what's in the store at that time, so in a buffered store, you are not performing a search over all records. 客户端过滤只能过滤当时存储中的内容,因此在缓冲存储中,您不会对所有记录进行搜索。 You would have to look into what ExtJS calls "remote filtering". 您将必须研究ExtJS所谓的“远程过滤”。 This means that ExtJS sends the filter parameters to the server and you have to implement the filter on the server side . 这意味着ExtJS将过滤器参数发送到服务器,并且您必须在服务器端实现过滤器 You are completely free to define a remote filter 您完全可以定义一个远程过滤器

property:'propertyThatTheStoreDoesntEvenKnowExists',
operator:'thisIsNotAnOperator',
value:'someValue'

and on the server side, you then have to implement a "filter function" that uses these variables (I use some pseudocode here): 然后在服务器端, 您必须实现使用这些变量的“过滤器功能”(我在此处使用一些伪代码):

filter = jsondecode(GET->filter);
if(filter->property=="propertyThatTheStoreDoesntEvenKnowExists" AND filter->operator=="thisIsNotAnOperator")
    result = mysql.buildQuery("SELECT * FROM table WHERE someProperty=@val").bind("@val",filter->value).execute();
else result = mysql.buildQuery("SELECT * FROM table").execute();

The store will then always contain all records that the server returns, no local filtering can be applied. 然后,存储将始终包含服务器返回的所有记录,无法应用本地过滤。

If you want to use client-side ("local") filtering, because you want to search the currently loaded set only, you can safely ignore all assumptions you have about MySQL features. 如果要使用客户端(“本地”)过滤,因为只想搜索当前加载的集合,则可以放心地忽略关于MySQL功能的所有假设。 What you have to care about is the strings that are returned to the client and can be found in the store. 您需要关心的是返回到客户端的字符串,这些字符串可以在商店中找到。 You are searching for perfect case-insensitive matches, so you can completely hand off regexp generation to ExtJS. 您正在寻找不区分大小写的完美匹配,因此可以将正则表达式生成完全交给ExtJS。

store.filter({
    property:'mySearchProperty',
    value:'rome',
    caseSensitive:false
})

should match Rome, rOme, ROME etc., but only searches the records that are in the store. 应该与Rome,rOme,ROME等匹配,但只能搜索存储中的记录。 So if you have a page size of 20, only the 20 records are searched and filtered down to those which contain that string. 因此,如果页面大小为20,则仅搜索20条记录并将其过滤为包含该字符串的记录。 In this case you are bound to the predefined operators; 在这种情况下,您必须绑定到预定义的运算符; or you can even define a custom function, which makes it possible to filter down about anything you want: 或者甚至可以定义一个自定义函数,从而可以过滤掉所需的任何内容:

var value = textfield.getValue().toLowerCase();
store.filter({
    filterFn:function(record) {
        return record.get("myProperty").toLowerCase().indexOf(value)>-1;
    }
})

But you cannot use both remote and local filtering on the same store. 但是您不能在同一存储上同时使用远程和本地筛选。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM