[619] | 1 | /* |
---|
| 2 | * Ext JS Library 2.2.1 |
---|
| 3 | * Copyright(c) 2006-2009, Ext JS, LLC. |
---|
| 4 | * licensing@extjs.com |
---|
| 5 | * |
---|
| 6 | * http://extjs.com/license |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | Ext.onReady(function(){ |
---|
| 10 | |
---|
| 11 | var ds = new Ext.data.Store({ |
---|
| 12 | proxy: new Ext.data.ScriptTagProxy({ |
---|
| 13 | url: 'http://extjs.com/forum/topics-remote.php' |
---|
| 14 | }), |
---|
| 15 | reader: new Ext.data.JsonReader({ |
---|
| 16 | root: 'topics', |
---|
| 17 | totalProperty: 'totalCount', |
---|
| 18 | id: 'post_id' |
---|
| 19 | }, [ |
---|
| 20 | {name: 'title', mapping: 'topic_title'}, |
---|
| 21 | {name: 'topicId', mapping: 'topic_id'}, |
---|
| 22 | {name: 'author', mapping: 'author'}, |
---|
| 23 | {name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'}, |
---|
| 24 | {name: 'excerpt', mapping: 'post_text'} |
---|
| 25 | ]) |
---|
| 26 | }); |
---|
| 27 | |
---|
| 28 | // Custom rendering Template |
---|
| 29 | var resultTpl = new Ext.XTemplate( |
---|
| 30 | '<tpl for="."><div class="search-item">', |
---|
| 31 | '<h3><span>{lastPost:date("M j, Y")}<br />by {author}</span>{title}</h3>', |
---|
| 32 | '{excerpt}', |
---|
| 33 | '</div></tpl>' |
---|
| 34 | ); |
---|
| 35 | |
---|
| 36 | var search = new Ext.form.ComboBox({ |
---|
| 37 | store: ds, |
---|
| 38 | displayField:'title', |
---|
| 39 | typeAhead: false, |
---|
| 40 | loadingText: 'Searching...', |
---|
| 41 | width: 570, |
---|
| 42 | pageSize:10, |
---|
| 43 | hideTrigger:true, |
---|
| 44 | tpl: resultTpl, |
---|
| 45 | applyTo: 'search', |
---|
| 46 | itemSelector: 'div.search-item', |
---|
| 47 | onSelect: function(record){ // override default onSelect to do redirect |
---|
| 48 | window.location = |
---|
| 49 | String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id); |
---|
| 50 | } |
---|
| 51 | }); |
---|
| 52 | }); |
---|