// 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);
#
2
03-08-2007, 11:52 PM
|
It sounds cool. Let me know when you have a link to look at.
|
#
3
03-09-2007, 06:59 AM
|
Modified editor grid example here:
http://ido.nl.eu.org/static/ext-1.0-...arch-grid.html |
#
4
03-09-2007, 07:29 AM
|
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: |
#
5
03-09-2007, 07:39 AM
|
|
Quote:
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. |
#
6
03-09-2007, 07:54 AM
|
I get
s has no properties http://ido.nl.eu.org/static/ext-1.0-alpha3/ext-all.js Line 214 sm is not defined http://ido.nl.eu.org/static/ext-1.0-...search-grid.js Line 174 |
#
7
03-09-2007, 07:58 AM
|
||
Quote:
Quote:
|
#
8
03-09-2007, 08:08 AM
|
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: |
#
9
03-09-2007, 02:52 PM
|
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?
|
#
10
03-09-2007, 03:38 PM
|
|
Quote:
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" }; 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) |