PDA

View Full Version : USE of table alias in store



gisernia
6 Apr 2012, 6:08 AM
I need to call a field with his alias table and column name, because calling the server.php i have queries with joins

this is the situation:


var grid = Ext.create('Ext.grid.Panel', {
features: [filters],
store: store,

// grid columns
columns:[{
text: '<?=$LBL_ACTIVITIES_FIELD_ACCOUNT_NAME?>',
dataIndex: 'TACCOUNT.NAME',
flex: 0.6,
align:'left',
filter: {type: 'string'}
},{
text: '<?=$LBL_ACTIVITIES_FIELD_NAME?>',
dataIndex: 'NAME',
filter: {type: 'string'},
flex: 0.6
},
in this case I have error and grid is not rendered. the problem is in the dot TACCOUNT.NAME

if I use


var grid = Ext.create('Ext.grid.Panel', {


features: [filters],
store: store,

// grid columns
columns:[{
text: '<?=$LBL_ACTIVITIES_FIELD_ACCOUNT_NAME?>',
dataIndex: 'TACCOUNT+NAME',
flex: 0.6,
align:'left',
filter: {type: 'string'}
},{
text: '<?=$LBL_ACTIVITIES_FIELD_NAME?>',
dataIndex: 'NAME',
filter: {type: 'string'},
flex: 0.6
},

and then a php replace of + with . in $sidx and it's all ok. How can I resolve in a better way?

mitchellsimoens
6 Apr 2012, 7:49 AM
The issue is that the way you were using a period is meaningful to javascript. It is assuming TACCOUNT is an object so it's looking for the NAME key.

In your Model you can try to use mapping and name to setup a model field that can account for this.

scottmartin
6 Apr 2012, 7:51 AM
I am not sure what you are doing here.

In PHP, using '.' to append a string, in JS, +
You have + inside your string


'TACCOUNT+NAME'

Did you want to append like: 'ACCOUNT'+'NAME' ?

You mention joins for field names.. why not just alias your fieldname in SQL
SELECT ALIAS.FIELD AS MYALIASFIELD

Regards,
Scott.

gisernia
6 Apr 2012, 8:35 AM
loading inizial data it's ok using aliases in sql-php.

i have problems when I try to sort and filter. If I call my column name from json I load like ACCOUNT.NAME AS NAME and it's ok. But If I sort, I send in REQUEST NAME ASC or NAME DESC and this is can be ambiguos for sql having some tables in join! :)

I'll try with field model asap

bye!

scottmartin
6 Apr 2012, 8:44 AM
You should be sending sort in a param and parsing that in PHP
Or you can also create a view and use that.



this.grid.store.load(
{
params: {
start: 0,
limit: globalPageSize, // initialized in modelSettings
sort: '[{"property":"user_name","direction":"ASC"}]' // defined in model as object
}
});

// php
function get_json_value($json,$key)
{
$result = NULL;
if(function_exists('json_decode')) {
$jsonData = json_decode($json, TRUE);
$result = $jsonData[0][$key];
}
return $result;
}

$sort = $this->get_json_value($this->input->get_post('sort', TRUE),'property');
$dir = $this->get_json_value($this->input->get_post('sort', TRUE),'direction');


Regards,
Scott.

gisernia
6 Apr 2012, 8:49 AM
thanks Scott.
Now I have hìjust to try your code.
I'll let you know if going well.
/:)