PDA

View Full Version : Get store field names to be set as params.



kdm
10 Dec 2012, 12:56 PM
What i'm trying to do is get a list of field names that i already defined in my objects JSONReader (pid, customer_id, location_id, etc...) and send them along as params when the store loads. The reason i'm doing this is so i don't need to define the columns in the JS code and my server-side php code. If I could just send the field names along in the params and use that in my SQL select statement that would save me time. How can I create a list or array of the field names and send them along in the param labeled column? Please see code below.



msc.grids.peopleGrid = Ext.extend(Ext.grid.GridPanel, {
border: false,
loadMask: true,
obj_id: '',
region: this.region,

initComponent:function() {
var config = {
frame: true,
store: new Ext.data.Store({
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
fields:[
{name: 'pid', type: 'int'},
{name: 'customer_id', type: 'string'},
{name: 'location_id', type: 'string'},
{name: 'ad_guid', type: 'string'},
{name: 'user_name', type: 'string'},
{name: 'password', type: 'string'},
{name: 'first_name', type: 'string'},
{name: 'last_name', type: 'string'},
{name: 'auth_type', type: 'string'},
{name: 'cell_phone', type: 'string'},
{name: 'business_phone', type: 'string'},
{name: 'home_phone', type: 'string'},
{name: 'fax', type: 'string'},
{name: 'text', type: 'string'},
{name: 'pager', type: 'string'},
{name: 'email', type: 'string'},
{name: 'status', type: 'string'},
{name: 'role', type: 'string'},
{name: 'technical_expertise', type: 'string'},
]
}),
sortInfo: {field: 'first_name', direction: "ASC"},
autoDestroy: true,
remoteSort: true,
groupOnSort: false,
remoteGroup: false,
proxy: new Ext.data.HttpProxy({
url: 'Views/peopleInfo.php',
method: 'POST'
})
}),
colModel: new Ext.grid.ColumnModel({
defaults: {
sortable: true
},
columns:[
{header: 'Id', dataIndex: 'pid', width: 20},
{header: 'First Name', dataIndex: 'first_name', width: 75},
{header: 'Last Name', dataIndex: 'last_name', width: 75},
{header: 'User Name', dataIndex: 'user_name', width: 70},
{header: 'Customer', dataIndex: 'customer_id', width: 75},
{header: 'Location', dataIndex: 'location_id', width: 150, hidden: true},
{header: 'AD GUID', dataIndex: 'ad_guid', width: 120, hidden: true},
{header: 'Password', dataIndex: 'password', width: 50, hidden: true},
{header: 'Authentication', dataIndex: 'auth_type', width: 50},
{header: 'Cell Phone', dataIndex: 'cell_phone', width: 100, hidden: true},
{header: 'Business Phone', dataIndex: 'business_phone', width: 100, hidden: true},
{header: 'Home Phone', dataIndex: 'home_phone', width: 100, hidden: true},
{header: 'Fax', dataIndex: 'fax', width: 100, hidden: true},
{header: 'Text', dataIndex: 'text', width: 100, hidden: true},
{header: 'Pager', dataIndex: 'pager', width: 100, hidden: true},
{header: 'Email', dataIndex: 'email', width: 100},
{header: 'Status', dataIndex: 'status', width: 75},
{header: 'Role', dataIndex: 'role', width: 100},
{header: 'Technical Expertise', dataIndex: 'technical_expertise', width: 100, hidden: true},
]
}),
viewConfig:{forceFit:true},
bbar: new Ext.PagingToolbar({
pageSize: 30,
store: this.store,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
}),
listeners: {
'beforerender': {
fn:function(){
this.getBottomToolbar().bindStore(this.store)
}
}
}
};

// apply config
Ext.apply(this, Ext.apply(this.initialConfig, config));
msc.grids.peopleGrid.superclass.initComponent.apply(this, arguments);
},

onRender:function(){
this.store.load(function(){
this.store.reader.meta.fields.each(function(record){
console.log(record.get('name'));
});
},{
params:{start:0, limit:30, format:'json', id: this.device_id, columns: field names here}
});
msc.grids.peopleGrid.superclass.onRender.apply(this, arguments);
console.log(this.store.reader.meta.fields);
}

});

Ext.reg('peopleGrid', msc.grids.peopleGrid);

kdm
10 Dec 2012, 2:38 PM
Looks like i solved my own problem.



onRender:function(){
var fieldNames = [];
this.store.fields.each(function(col){
fieldNames.push(col.name);
});
var select = fieldNames.join();
this.store.load({params:{start:0, limit:30, format:'json', id: this.obj_id, columns: select}});
msc.grids.peopleGrid.superclass.onRender.apply(this, arguments);
}