Combine paging, Ext.Template and a remote data store to create a "live search" feature.
<!--
/*!
* Ext JS Library 3.0.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
-->
<html>
<head>
<title>Hello World Window</title>
<link rel="stylesheet" type="text/css" href="ext-3.0.0/resources/css/ext-all.css" />
<script type="text/javascript" src="ext-3.0.0/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext-3.0.0/ext-all.js"></script>
<!-- The box wrap markup embedded instead of using Element.boxWrap() -->
<div style="width:600px;">
<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc"></div></div></div>
<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">
<h3 style="margin-bottom:5px;">Search the Ext Forums</h3>
<input type="text" size="40" name="search" id="search" />
<div style="padding-top:4px;">
Live search requires a minimum of 4 characters.
</div>
</div></div></div>
<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc"></div></div></div>
</div>
</head>
<!-- Revised from demo code in ext3.0.0 -->
<body>
<script type="text/javascript">
/*!
* Ext JS Library 3.0.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/
Ext.onReady(function(){
var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://extjs.com/forum/topics-remote.php'
}),
reader: new Ext.data.JsonReader({
root: 'topics',
totalProperty: 'totalCount',
id: 'post_id'
}, [
{name: 'title', mapping: 'topic_title'},
{name: 'topicId', mapping: 'topic_id'},
{name: 'author', mapping: 'author'},
{name: 'lastPost', mapping: 'post_time', type: 'date', dateFormat: 'timestamp'},
{name: 'excerpt', mapping: 'post_text'}
])
});
// Custom rendering Template
var resultTpl = new Ext.XTemplate(
'<tpl for="."><div class="search-item">',
'<h3><span>{lastPost:date("M j, Y")}<br />by {author}</span>{title}</h3>',
'{excerpt}',
'</div></tpl>'
);
var search = new Ext.form.ComboBox({
store: ds,
displayField:'title',
typeAhead: false,
loadingText: 'Searching...',
width: 570,
pageSize:10,
hideTrigger:true,
tpl: resultTpl,
applyTo: 'search',
itemSelector: 'div.search-item',
onSelect: function(record){ // override default onSelect to do redirect
window.location =
String.format('http://extjs.com/forum/showthread.php?t={0}&p={1}', record.data.topicId, record.id);
}
});
});
</script>
</div>
</body>
</html>
Related examples in the same category