PDA

View Full Version : [S] COMBOBOX - Create Store in event click(expand)



Laufwerk
11 Jun 2009, 11:58 PM
Hello !!
I need qhe the user click to dropdown list, throw a query to filling up her store.
I have this code:


customer_nameField = new Ext.form.ComboBox({
id: 'customer_name',
fieldLabel: "Client ",
maxLength: 60,
allowBlank: true,
anchor: '95%',
hidden: false,
hideLabel: false,
// store: new Ext.data.SimpleStore({
// fields: ["id", "description"],
// data : [["nombre1","cif1"],["nombre2","cif2"]]
// }),
displayField: 'id',
valueField: 'id',
mode: 'local',
listeners: {
select:
function(el,type){
customer_codeField.setValue(type.data.cif);
},
expand:
function(el,type){
var myArrayData;
myArrayData = getCustomers();
}
}
});

function getCustomers(){
Ext.Ajax.request({
waitMsg: "Si us plau, esperi...",
url: 'modules/invoices/sections/delivery_notes/include/database.php',
params: {
task: "GETCUSTOMERS",
},
success: function(response){
var result=eval(response.responseText);
switch(result){
case 1:
Ext.utiles.msg("OK", "S'ha desat correctament.");
DataStore.reload();
CreateWindow.close();
break;
default:
Ext.utiles.msg("Atenció", "No s'ha pogut crear.");
break;
}
},
failure: function(response){
var result=response.responseText;
Ext.utiles.msg("Error", "No s'ha pogut connectar amb la base de dades. Intenti-ho més tard");
}
});
}

For the moment the event is correct but ever display me succes - default.

How I can do it?

Anticipated Thanks

Sorry ! This threat is for Ext Comunity Forums (2.0) - Ext: Help

Laufwerk
12 Jun 2009, 12:04 AM
Hi again!
I only need knows, how to add store in my comboBox


thanks!

nikhilkrishnan
12 Jun 2009, 4:48 AM
D you want to fill the store remotely, i mean from a database?

Laufwerk
12 Jun 2009, 4:57 AM
yes, I'm trying to get data from server, but I haven't the code. Can u help me?

nikhilkrishnan
13 Jun 2009, 7:28 PM
Hi,

This is how you can load the store from a db


combodata=new Ext.data.Store({
id:id,
proxy:new Ext.data.HttpProxy({
url:'database.php' (http://extjs.com/forum/'database.php'),
method:'POST'
}),//HttpProxy
baseParams:{task:" "},
reader:new Ext.data.JsonReader({
root:'results',
totalproperty:'total',
id:'id'},
[
{name:'result',type:'string',mapping:'result'},
]),//READER
sortInfo:{field:'result',direction:"ASC"}
});

as this is a json reader you need to send the data back the client in json format. I got a php file from this site that converts the data to json.

Laufwerk
14 Jun 2009, 10:26 PM
hi again!
Why u put empty text in task in baseParams:{task:" "},???

Thanks

Laufwerk
15 Jun 2009, 12:59 AM
finally works fine, thanks all!!!

file *.js


var dsCustomersCIFs;
dsCustomersCIFs = new Ext.data.Store({
id:'id'
,proxy: new Ext.data.HttpProxy({
url: 'database.php'
,method: 'POST'
})
,baseParams:{task: 'GETCUSTOMERS'} // this parameter is passed for any HTTP request
,reader: new Ext.data.JsonReader({
root: 'results'
,totalProperty: 'total'
,id: 'id'
},[
{name: 'name', type: 'string'},{name: 'cif', type: 'string'}
])
,sortInfo:{field: 'name', direction: 'ASC'}
,remoteSort: true
});

customer_nameField = new Ext.form.ComboBox({
id: 'customer_name',
fieldLabel: "Client ",
maxLength: 60,
allowBlank: true,
anchor: '95%',
hidden: false,
hideLabel: false,
triggerAction: 'all',
allQuery: '',
minChars: 0,
store: dsCustomersCIFs,
displayField: 'name',
valueField: 'name',
mode: 'remote',
listeners: {
select: function(el,type){
customer_codeField.setValue(type.json.cif);
}
}
});


database file .php


$task = (isset($_POST['task']) ? $_POST['task'] : $_GET['task']);
switch($task){

case "GETCUSTOMERS":
if ($edit!=0){
// TIENE PERMISOS PARA LA EDICION
getCustomers($db_company);
}
break;
}

function getCustomers($db){
$query="SELECT name,cif FROM tablename";
$queryRecibida =(isset($_POST['query']) ? $_POST['query'] : $_GET['query']);

// Here we check if we have a query parameter :
if (isset($queryRecibida)){
// SI EL USUARIO ESCRIBE EN EL CAMPO DE BÚSQUEDA RÁPIDA AÑADIMOS A LA QUERY LOS PARAMETROS A BUSCAR
$query .= " WHERE name LIKE '%".$queryRecibida."%'";
}

$result = &$db->Execute($query);
$nbrows = $result->RecordCount();
if($nbrows>0){
$myString="[";
while ( !$result->EOF ){
// Para campos del tipo fecha haremos lo siguiente:
$arr[] = $result->fields;
$result->MoveNext();
}
}

$jsonresult = JEncode($arr);
echo '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';

}



thanks again!