开发者

Extjs store filtering - include metachars

开发者 https://www.devze.com 2023-04-09 00:43 出处:网络
I have a data store having a Note field (a textarea) and want to display all Notes satisfying a user input (even metacharacters).

I have a data store having a Note field (a textarea) and want to display all Notes satisfying a user input (even metacharacters).

I've written the following function to handle this:

function notefilter() {
    var newfilter = Ext.getCmp('searchnote');
    var searchStr = newfilter.getValue();
    searchStr = searchStr.replace('?', '\\?').replace('*', '\\*').replace('+', '\\+').replace('{', '\\{').replace('}', '\\}').replace('[', '\\[').replace(']', '\\]').replace('(', '\\(').replace(')', '\\)').replace('|', '\\|').replace('$', '\\$').replace('^', '\\^');

    var re = new RegExp(".*" + searchStr + ".*开发者_开发知识库", "ig");
    Ext.getCmp('notesgrid').store.filter('Note', re);
}

However the filter fails to search for metacharacters even after escaping them, but it works are all other alphanumeric input.

Am I missing something ?

Thanks in advance !


Finally, got the filter working. JavaScript's built in escape() & encodeURIComponent() did the work for me. I do not have to programatically escape the metachars.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号