PDA

View Full Version : Grid Panel -> Form Display



gr0uch0
27 Sep 2010, 5:19 AM
Hi,
ExtJS newbie here having a headsplitting time trying to discover the answer to what appears to be a rather simple question.

I'm using JsonStore to populate a grid with a summary of all the data required. The rest of the fields are to be populated into a tabbed form (in another ViewPort area) with the values changing when the user selects a different row in the grid. I can get this to work using template updates, the trouble with that is that it uses HTML for the field creation and is going to take ages formatting and CSSing each field, plus I won't get field validation working. I thing what I need is a method of doing this using xtype fields.

Would anyone like to put me out of my misery - it's either that or the 'puter will be on the wrong end of a 2 pound hammer :-)

gr0uch0
28 Sep 2010, 1:37 AM
Well the weight of the hammer is increasing, it's 5 pounds now!

I think I've constructed everything OK from butchering serveral examples and have come up with the following code.
I just can't get the glue to work - the RowSelectionModel seems to be selecting the row OK but the tabbed form in viewport's EAST is not updating. Anyone got any ideas please?



Ext.onReady(function() {

Ext.QuickTips.init();

//turn on validation errors
Ext.form.Field.prototype.msgTartget = 'side';

var bd = Ext.getBody();

// create the Data Store
var ds = new Ext.data.JsonStore({url: 'grid-data.php',
fields:[{name:'eventid'}
,{name:'eventname'}
,{name:'event_type'}
,{name:'event_start_date', type:'date', dateFormat:'Y-m-d'}
,{name:'event_start_time', type:'time'}
,{name:'event_end_date', type:'date', dateFormat:'Y-m-d'}
,{name:'event_end_time', type:'time'}
]
}); //eo store
//load data from the php url
ds.load();

//create the default column model
var colModel = new Ext.grid.ColumnModel([
{id:'ID',header:"ID",width:1, sortable:true,dataIndex:'eventid'}
,{header:"Event Name",width:10,sortable:true,dataIndex:'eventname'}
,{header:"Event Type",width:10,sortable:true,dataIndex:'event_type'}
,{header:"Start Date",width:6,sortable:true,renderer:Ext.util.Format.dateRenderer('d M Y'),dataIndex:'event_start_date'}
,{header:"Start Time",width:5,sortable:false,dataIndex:'event_start_time'}
,{header:"End Date",width:6, sortable:true, xtype:'datecolumn', format: 'M d, Y',dataIndex:'event_end_date'}
,{header:"End Time",width:5,sortable:false,dataIndex:'event_end_time'}
]);



var grid = new Ext.grid.GridPanel({
id:'event-grid'
,xtype:'grid'
,autoheight:true
,viewConfig: {forceFit: true}
,height:210
,split: true
,region: 'center'
,store: ds
,colModel: colModel
,sm: new Ext.grid.RowSelectionModel({singleSelect: true})
,layout:'fit'
,listeners: {
viewready: function(g) {
g.getSelectionModel().selectRow(0);
}
}
});






Ext.BLANK_IMAGE_URL = './s.gif';

handleAction = function(action){
Ext.example.msg('<b>Action</b>', 'You clicked "'+action+'"');
};

//toolbar definitions for the center panel
tbar = new Ext.Toolbar({
enableOverflow: true,
items: [{
xtype:'splitbutton'
,text: 'Print'
,iconCls: 'add16'
,handler: handleAction.createCallback('Print')
,menu: [
{text: 'Event Summary', handler: handleAction.createCallback('Event Summary')}
,{text: 'Detailed Event', handler:handleAction.createCallback('Detailed Event')}
]
},'-',{
xtype:'splitbutton'
,text: 'Test1'
,iconCls: 'add16'
,handler: handleAction.createCallback('Test1')
,menu: [{text: 'Test1', handler: handleAction.createCallback('Test1')}]
},{
text: 'Test2'
,iconCls: 'add16'
,handler: handleAction.createCallback('Test2')
},'-']
});


var viewport = new Ext.Viewport({
id:'simplevp',
layout:'border',
border:false,
items:[
//NORTH
{
region:'north'
,id:'north'
,height:100
,border:false
,bodyStyle:'background-color:#f8f8f8;'
,title:'North'
,collapsible:true
,collapsed:true
}
,{
//WEST
region: 'west'
,layout: 'border'
,bodyStyle:'padding:5px;font-size:11px;background-color:#f4f4f4;'
,border: false
,width:200
,minimizable: true
,collapseMode:'mini'
,split:true
,autoScroll:false
,items: [
{region:'north'
,border:false
},{region: 'center'
,id: 'westnorth'
,title: 'Bits and Bobs'
//,collapsible:true
,autoscroll:true
//,split: true
//,collapseMode:'mini'
,height: 150
},{region:'south'
//,split: true
,autoscroll:true
,height:500
,html:'<div id="tree"> area for DIV ID=TREE </div>'
}
]
},
{
//EAST
region:'east'
,id:'eventTabPanel'
,width:390
,minimizable: false
,split:true
,collapsible: false
,collapseMode:'mini'
,bodyStyle:'background-color:#f4f4f4;'
,title: 'Event Details'
,layout:'fit'
,items:[{
xtype:'multirowtabpanel'
,enableTabScroll:true
,multipleRows:true
,activeItem:0
,border:false
,anchor:'100% 100%'
,deferredRender:false
,defaults:{layout:'form',labelWidth:100,defaultType:'textField',bodyStyle:'padding:5px',hodeMode:'offsets'
// ,html: 'Please select an event from the grid to see additional details.'}
,items:[
{title:'General Information',id: 'generalPanel'
,items:[
{ xtype: 'textfield', fieldLabel: 'Event ID', name: 'eventID', anchor: '50%', disabled: 'true'}
,{ xtype: 'textfield', fieldLabel: 'Event Name', name: 'eventName', anchor: '95%'}
,{ xtype: 'textfield', fieldLabel: 'Customer', name: 'customer', anchor: '95%'}
,{ xtype: 'datefield', fieldLabel: 'Start Date', name: 'startDate', anchor: '95%',format: 'd M Y' }
,{ xtype: 'datefield', fieldLabel: 'End Date', name: 'endDate', anchor: '95%',format: 'd M Y' }
]}
,{title:'Staff Requirement',id: 'staffPanel'}
,{title:'Transport Requirement',id: 'transportPanel',layout:'form'}
,{title:'Equipment',id: 'equipmentPanel'}
,{title:'Accomodation',id: 'accomodationPanel'}
,{title:'Catering',id: 'cateringPanel'}
,{title:'Marketing',id: 'marketingPanel'}
,{title:'Finance',id: 'financePanel'}
]
}]
},{
//CENTER
region:'center'
,items:[
{region: 'north',items:[tbar]}
,{region:'center',items:[grid]}
// ,{region:'south',xtype: 'calendarpanel'}
]}
]
,renderTo:bd
});



});
//entryPoint



// eof