PDA

View Full Version : How to filter data from a DB based on what I type



dkarakostis
1 Apr 2015, 4:22 AM
I have created an ExtJS (EXtjs4) app where I have a combo box and populate it with values from the database.


This my code.
First my store:


var autoCompleteStore = new Ext.data.JsonStore({
fields:['onomasia'],
proxy: new Ext.data.HttpProxy({
url: 'autocomplete/getautocomplete.php',
method: 'POST'
}),
baseParams:{task: "onomasia"}
});


The combo box definition:


// DEFINE THE COMBO BOX FOR THE AUTOCOMPLETE
var nodeOikismoiField = new Ext.form.ComboBox({
id:'nodeId',
fieldLabel: 'Insert NodeId',
store: autoCompleteStore,
mode: 'remote',
displayField: 'onomasia',
allowBlank: false,
valueField: 'onomasia',
anchor:'95%',
triggerAction: 'all',
name: 'oikismos',


labelAlign : 'right',
width: 200,
margin: 5,
minChars:1
});



and my PHP script:


<?php
include 'postgresConnect.php';
$query = "SELECT onomasia FROM oikismoi_covered LIMIT 3";
$resultImg = pg_query($dbconn, $query);
$json=array();
while($oikismos=pg_fetch_row($resultImg)){
$json[]=array(
'onomasia'=> $oikismos[0]
);}
echo json_encode($json);
?>




My question is the following:
When I start typing something on the Combo, how can I get only the possible values? For example if I start typing "Ae..." to get only the values starting with these letters.


I realise that I have to change my sql query in the php file and also pass the value in there.
But what part of code should I change in the ExtJS part?

skirtle
1 Apr 2015, 7:40 PM
Your code looks a lot like ExtJS 3 to me. Several of those config settings don't exist in ExtJS 4 and most of those class names have changed between versions.

If you are using ExtJS 4 I'd suggest reading this:

http://skirtlesden.com/articles/extjs-comboboxes-part-1

Part 2 covers remote filtering though I'd suggest working carefully through part 1 first.

dkarakostis
1 Apr 2015, 10:31 PM
Thank you. I will read it carefully.