ext 1.0 alpha3 combobox history - Ext JS

本文介绍了一个快速搜索字段的实现方案,该方案适用于大型数据集的网格视图,并且具备历史记录功能。通过使用Ext框架,实现了输入框的自动完成、过滤及快速搜索功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

hi all,

i'm working on a quicksearch field for the grid with a (limit) history
while it's far from perfect, i wanted to share the code with u
using the editor-grid and paging example:

[edit]
i made a follow up grid demo @ http://ido.nl.eu.org/pir/
which has history completion and does both filtering and quicksearch
over a very large dataset.
[/edit]

Demo: http://ido.nl.eu.org/static/ext-1.0-...arch-grid.html
            // header panel
            var gridHead = grid.getView().getHeaderPanel();
            gridHead.show();
            var tb = new Ext.Toolbar(gridHead);

            tb.add({
                text: 'Quicksearch:',
                tooltip: 'Quickly search through the overview.',
            });

            var sftb = tb.addDom({
                tag: 'input',
                id: 'quicksearch',
                type: 'text',
                size: 30,
                value: '',
                style: 'background: #F0F0F9;'
                });
            var searchStore = new Ext.data.SimpleStore({
                fields: ['query'],
                data: []
            });
            var searchBox = new fm.ComboBox({
                store: searchStore,
                displayField: 'query',
                typeAhead: false,
                mode: 'local',
                triggerAction: 'all',
                hideTrigger: true,
            });
            searchBox.applyTo('quicksearch');
            tb.add({
                text: 'X',
                tooltip: 'Clear quicksearch',
                handler: function() {
                    if (searchBox.getValue().length!=0) {
                        searchBox.setValue('');
                        ds.clearFilter();
                    }
                }
            });
            var searchRec = Ext.data.Record.create([
                {name: 'query', type: 'string'}
            ]);
            var onFilteringBeforeQuery = function(e) {
                if (this.getValue().length==0) {
                    ds.clearFilter();
                } else {
                    var value = this.getValue().replace(/^\s+|\s+$/g, "");
                    if (value=="")
                        return;
                    ds.filterBy(function(r) {
                        valueArr = value.split(/\ +/);
                        for (var i=0; i<valueArr.length; i++) {
                            re = new RegExp(Ext.escapeRe(valueArr[i]), "i");
                            if (re.test(r.data['Title'])==false
                                && re.test(r.data['Place'])==false
                                && re.test(r.data['Remarks'])==false) {
                                return false;
                            };
                        }
                        return true;
                    });
                }
            };
            var onQuickSearchBeforeQuery = function(e) {
                if (this.getValue().length==0) {
                } else {
                    var value = this.getValue().replace(/^\s+|\s+$/g, "");
                    if (value=="")
                        return;
                    searchStore.clearFilter();
                    var vr_insert = true;
                    searchStore.each(function(r) {
                        if (r.data['query'].indexOf(value)==0) {
                            // backspace
                            vr_insert = false;
                            return false;
                        } else if (value.indexOf(r.data['query'])==0) {
                            // forward typing
                            searchStore.remove(r);
                        }
                    });
                    if (vr_insert==true) {
                        searchStore.each(function(r) {
                            if (r.data['query']==value) {
                                vr_insert = false;
                            }
                        });
                    }
                    if (vr_insert==true) {
                        var vr = new searchRec({query: value});
                        searchStore.insert(0, vr);
                    }
                    var ss_max = 4; // max 5 query history, starts counting from 0; 0==1,1==2,2==3,etc
                    if (searchStore.getCount()>ss_max) {
                        var ssc = searchStore.getCount();
                        var overflow = searchStore.getRange(ssc-(ssc-ss_max), ssc);
                        for (var i=0; i<overflow.length; i++) {
                            searchStore.remove(overflow[i]);
                        }
                    }
                }
            };
            searchBox.on("beforequery", onQuickSearchBeforeQuery);
            searchBox.on("beforequery", onFilteringBeforeQuery);
            searchBox.on("select", onFilteringBeforeQuery);
it only remembers to longest unique line and forgets all the typing in between.
hoping to get it to work with explicitly typing enter to get a query into history,
this way just type away to quickfind and explicitly remember a query for later.

(this would also make much sense to user who just put <enter> after everything)

thanks to Jack for this new combobox to play with
Reply With Quote
  #2  
Old 03-08-2007, 11:52 PM
Default

It sounds cool. Let me know when you have a link to look at.
Reply With Quote
  #3  
Old 03-09-2007, 06:59 AM
Default

Modified editor grid example here:

http://ido.nl.eu.org/static/ext-1.0-...arch-grid.html
Reply With Quote
  #4  
Old 03-09-2007, 07:29 AM
Default

trbs -- looks great...

small issue... if you type "sun" and wait a while... then using backspace to just "s" and write "shadow" then the history will contain both "sun" and "shadow". Maybe it could be a configuration parameter.... if you delete something while you are editing then I would not have it in the history. :wink:
Reply With Quote
  #5  
Old 03-09-2007, 07:39 AM
Default

Quote:
Originally Posted by KimH
trbs -- looks great...

small issue... if you type "sun" and wait a while... then using backspace to just "s" and write "shadow" then the history will contain both "sun" and "shadow". Maybe it could be a configuration parameter.... if you delete something while you are editing then I would not have it in the history. :wink:
yeah that's a known problem
quicksearch should filter the datastore as u type (otherwise it's not very quick :-)
but the history should be meaningfull and not contain every variation one types. that's why i made it so it only remembers the longest unique line.

this brings forward your issue, and is also terrible for typo's, eg; type 'shadows' while u mean 'shadow' and the longer/bad search query is remembered in history instead of the correct one.

that is why i want to try and hook into keyup instead of beforequery for the history. making it so that the history would only remember query's after u press <enter> in the searchbox.
Reply With Quote
  #6  
Old 03-09-2007, 07:54 AM
Default

I get

s has no properties http://ido.nl.eu.org/static/ext-1.0-alpha3/ext-all.js Line 214
and

sm is not defined http://ido.nl.eu.org/static/ext-1.0-...search-grid.js Line 174
Reply With Quote
  #7  
Old 03-09-2007, 07:58 AM
Default

Quote:
Originally Posted by Animal
I get

s has no properties http://ido.nl.eu.org/static/ext-1.0-alpha3/ext-all.js Line 214
Working on this one....
Quote:
Originally Posted by Animal
and

sm is not defined http://ido.nl.eu.org/static/ext-1.0-...search-grid.js Line 174
Sorry about that, should not work in javascript i posted while trying to track down the 's has no properties' problem
Reply With Quote
  #8  
Old 03-09-2007, 08:08 AM
Default

Fixed the 's has no properties' error...
Works fine with the RowSelectionModel, still havn't got my finger on the underlying problem with CellSelectionModel...

but it works now, without errors, in Firefox/Firebug which is good enough for the demo i guess :wink:
Reply With Quote
  #9  
Old 03-09-2007, 02:52 PM
Default

It worked great for me. I was wondering, can this work against a paged, remote data source. Well, I know it can ...but does what you have done work that way? In other words, if I want this to work on a table that would have 100k records I would not necessarily want to load all of those records into the page. Ideas?
Reply With Quote
  #10  
Old 03-09-2007, 03:38 PM
Default

Quote:
Originally Posted by lstroud
It worked great for me. I was wondering, can this work against a paged, remote data source. Well, I know it can ...but does what you have done work that way? In other words, if I want this to work on a table that would have 100k records I would not necessarily want to load all of those records into the page. Ideas?
i build it for a paged grid, but it only filters thru the page not all the records in the store.
if you would like to show 20 records on a page but search thru 100k then i think
you should take a look at Jack's autocompletion box. (forum-search.html)

i guess my example could go as far as filtering the grid store server side and displaying (in pages) all the results of the search in the grid. however, i would not recommend this for a 'quicksearch' because sending a query to the server for every letter a client types could easily bring down the server with a few users.

Once i'm able to handle the onKeyUp events nicely in the searchbox it would make a nice feature for a grid application to do what you want on pressing enter in the searchbox (not at every stroke). If the searchbox was intergrated more tightly with the grid and pagingtoolbar (read; if i build a separate component extending combobox instead of just using it in the example) this could be something like an option on the searchbox.

I hope to get around to extending combobox to make something like a searchbox as soon as possible.

Jack, maybe it's an idea to add another parameter to Store.js ?
so that we have something like:
this.paramNames = {
        "start" : "start",
        "limit" : "limit",
        "sort" : "sort",
        "dir" : "dir",
        "filter" : "filter"
    };
Where 'filter' could be a dictionary of column and filter values or something like that.
To be able to do server side filtering of the store when datasets get really really large.
This could also be usefull if you want to have a selectbox somewhere else on the page or gridheader too only view records with a specific condition in the grid. (for example; having a selectbox with "Sunny" / "Shady" / etc somewhere and only show plants which are Sunny in the grid)
Reply With Quote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值