javascript - ExtJS - How to filter data from a DB based on what I type -


i have created extjs (extjs4) app have combo box , populate values database.

this code. first 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 combo box 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,                 typeahead: true, // changes                 typeaheaddelay: 200,// changes                 queryparam: 'query' // changes  }); 

and php script: edited

<?php  include 'postgresconnect.php';  $where = '';  $queryvar = $_get['query']; // instead of post  $where = " komvos '$queryvar%' ";  $query = "select komvos oikismoi_covered $where";   $resultimg = pg_query($dbconn, $query);  $json=array();  while($oikismos=pg_fetch_row($resultimg)){      $json[]=array(                 'onomasia'=> $oikismos[0]     ); } echo json_encode($json); ?> 

my question following: when start typing on combo, how can possible values? example if start typing "ae..." values starting these letters.

i realise have change sql query in php file , pass value in there. part of code should change in extjs part?

in php script need this:

$where = ''; if (isset($_post['query'])) {    $queryvar = $_post['query'];    $where = " `onomasia` '$queryvar%' " }  $query = "select onomasia oikismoi_covered $where limit 3";  

please bear in mind particular query open mysql injection attacks , should sanitized beforehand, or use prepared statements pdo better.

in combo definition should apply typeahead , typeaheaddelay configs

these configs should help:

typeahead: true, typeaheaddelay: 200, querymode: 'remote', queryparam: 'query' // parameter name passed php  

this link should more details.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -