PDA

View Full Version : populate column heads from database for columngrid



durgasanthi
15 Jun 2008, 11:46 PM
how can I populate column heads from database, i.e., I need to print dynamicaclly from different table from database.

For this I have searched forums, but could n't find any solution for my problem.

My code:

Ext.onReady(function(){

Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var ds = new Ext.data.JsonStore({
url:'http://192.168.1.130:8103/v2_dev/ext-2.1/rw_sp/getReportData.php?cat_num='+cat_num[0]+"&rptType="+cat_num[1]+"&sid="+cat_num[2]+"&pid"+cat_num[3]+"&rid="+cat_num[4],
id: 'sku',
totalProperty: 'total',
root: 'data',
fields: [
{name:'sku',type:'int'},
{name:'model_no',type:'string'},
{name:'loc',type:'string'},
{name:'price',type:'float'},
{name:'ace_retail_price',type:'float'},
{name:'qoh',type:'int'},
{name:'vendor',type:'string'} ,
{name:'product',type:'string'},
{name:'lw_retail_price',type:'float'},
{name:'hd_retail_price',type:'float'}

],
sortInfo: {field: 'sku', direction: 'asc'}
//remoteSort: true
});


var cm = new Ext.grid.ColumnModel([
{dataIndex: 'sku', header: 'Sku done123',sortable: true},
{dataIndex: 'model_no', header: 'Model No', id: 'model_no',sortable: true},
{dataIndex: 'loc', header: 'Loc',sortable: true},
{dataIndex: 'price', header: 'Price',sortable: true},
{dataIndex: 'ace_retail_price', header: 'Ace Petail Price',sortable: true},
{dataIndex: 'qoh', header: 'Qoh',sortable: true},
{dataIndex: 'vendor', header: 'Vendor',sortable: true},
{dataIndex: 'product', header: 'Product',sortable: true},
{dataIndex: 'lw_retail_price', header: 'LW Retail Price',sortable: true},
{dataIndex: 'hd_retail_price', header: 'HD Retail Price',sortable: true}
]);
//cm.defaultSortable = true;
if(cat_num[1] == 'hle'){
var grid = new Ext.grid.GridPanel({
id: 'example',
title: 'Hi/Lo/Equal',
ds: ds,
cm: cm,
enableColLock: false,
loadMask: true,
height:600,
width:800,
el: 'grid-example2',
//autoExpandColumn: 'model_no',

});
}else{
var grid = new Ext.grid.GridPanel({
id: 'example',
// title: 'Price Comparison Report',
ds: ds,
cm: cm,
enableColLock: false,
loadMask: true,
height:400,
width:1000,
el: 'grid-example2',
//autoExpandColumn: 'model_no',
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: ds,
displayInfo: true,
displayMsg: 'Displaying records {0} - {1} of {2}',
emptyMsg: "No topics to display",
plugins: new Ext.ux.grid.PageSizer()
})
});

}



grid.render();

ds.load({params:{start: 0, limit: 10}});
});


Immediate help would be appreciated and Thanks in advance..