PDA

View Full Version : Create data.store with params



blade226
5 Jun 2012, 4:00 AM
Hello,
i have a grid and i want to open a window on selectionchange

artikelGrid = Ext.create ("Ext.grid.Panel" , {
store : store_traeger,
autoScroll : true,
itemId: 'tabtraeger',

//features: [{ftype:'grouping'}],
frame:true,
columns:[
{header:"ID",dataIndex:"tra_id"},
{header:"Name",dataIndex:"tra_name"},
{header:"Vorname",dataIndex:"tra_vorname"}
],
listeners: {
selectionchange: function(model,records){


This Part works. But in the new window the script should be open a php-script witch sends back more informations for the selected record.

selectionchange: function(model,records){

Ext.Ajax.request({
url:"includes/konto.php",
});

var kontodaten = Ext.create('Ext.data.Store', {

fields:['fuid_konto','fuid_traeger','kontoinhaber'],
proxy : {
type:"ajax",
//params: records[0].data,
url:"includes/konto.php",
//params: records[0].data,
waitMsg: 'Loading...',
reader:{
type:"json"
},
writer: {
type: 'json'
}
},
autoLoad:true,
autoSync: true

});

I tried it with

params: records[0].data in the proxy part, but no records send to the php-script

When i use

Ext.Ajax.request({
url:"includes/konto.php",
params: records[0].data
});

all needed informations will be send, but how can i create the store?

Thx for response

vela1606
5 Jun 2012, 4:57 AM
use the proxy extraParams property. like this....



proxy : {
type: 'ajax',
url: 'includes/konto.php'
extraParams: {
data: records[0].data
}
}


to send params using ajax reauqest...



Ext.Ajax.request({
url: 'includes/konto.php',
params: {
data: records[0].data
},
success: function(response){
var text = response.responseText;
// process server response here
}
});

blade226
6 Jun 2012, 1:56 AM
It works, but how can i get the different variables.
Here is the code

Ext.Ajax.request({
url: 'includes/konto.php',
params: {
data: records[0].data
},
success: function(response){
var text = response.responseText;
var kontodaten = Ext.create('Ext.data.Store', {

fields:['fuid_konto','fuid_traeger','kontoinhaber'],
proxy : {
type:"ajax",
//params: records[0].data,
url:"includes/konto.php",
extraparams: {
data: records[0].data
},
waitMsg: 'Loading...',
reader:{
type:"json"
},
writer: {
type: 'json'
}
},
autoLoad:true,
autoSync: true

});
}
});


For example ext posts this variables (copy of firebug response):
data 1
data Testtraeger
data Vornat

How can i split the data expression? For php i need the variable 1

I tried:

$result = mysql_query("SELECT * FROM traeger_konto where fuid_traeger = '".$data[0]."'") or die("Query failed : " . mysql_error());


And then
How must the json string looks like? and how can i put it in an store. I'm not sure that the code works!

I imagine the data record so:


[{"success":"true"}

{ "konto": [ { "id": 1, "name": "test", "ktonr": "4711" }, { "id": 2, "name": "tester", "ktonr": "9985" } ]
"ansprechpartner": [ { "id": 1, "name": "Meier" }, { "id": 2, "name": "Schmidt" } ] }]Is this correct and how can i transport it in a store.
I hope that I could present my problems to understand

vela1606
6 Jun 2012, 5:10 AM
sorry, don't understand what you are trying to achieve.

is your code open source? can you post more of your code? or a link to a repository?

are you using php function json_decode?

vela1606
6 Jun 2012, 5:25 AM
$data = json_decode($_REQUEST, true)



then to use "data 1" do $data['1']
to use "data Testtraeger" do $data['Testtraeger']
to use "data Vornat" do $data['Vornat']

blade226
20 Jun 2012, 11:33 PM
I find no solution to my problem!

I still hang on my problem with the creation of a store, after transfer to a new window. I hope that once you find time to help me:


selectionchange: function(model,records){
Ext.Ajax.request({
url: 'includes/konto.php',
params: {
tra_id: records[0].get('tra_id')
},

->Here is also a record is passed to the konto.php
->Firebug: tra_id 1

-> in konto.php stands:$tra_id = $_POST["tra_id"];
->With the variable should be continued. But it is empty

->I let my sql command to return again as json:: [{"success":"true","sql":"SELECT * FROM traeger_konto where fuid_traeger = ''"}]

success: function(response){

My intention is:

on selectionchange in the grid:

1: execute konto.php with the selected row
2: open a new window with tabs
3: parse the results of konto.php in different tabs of the new window