PHP Code:
var employee_model = Ext.data.Record.create(['empl_id','fullname','first']);
var phone_model = Ext.data.Record.create(['phone_id','phone']);
var employees = new Ext.data.ArrayStore({
fields:employee_model,
idIndex: 0
});
var phones = new Ext.data.ArrayStore({
fields:phone_model,
idIndex: 0
});
var myData = [
[1, 'Fred Flintstone', 'Fred'],
[2, 'Barney Rubble', 'Barney']
];
employees.loadData(myData);
var myPhones = [
[1, '07981167840'],
[2, '00441234566']
];
phones.loadData(myPhones);
var text_editor = new Ext.form.TextField();
function show_employees() {
var contentDiv = Ext.get('contentDiv');
var employees_grid = new Ext.grid.EditorGridPanel({
autoExpandColumn: 'empl-col-full',
frame:false,
title: 'Employees',
height:300,
width:330,
store: employees,
tbar: [
{
text: 'Add new employee',
iconCls:'add',
handler: function(){
var r= new employee_model ({
empl_id: 0,
fullname: '',
first: ''
});
employees_grid.stopEditing();
employees.insert(0,r);
employees_grid.startEditing(0,0);
}
},'-'
],
columns: [
{id: 'empl-col-first', header: 'First name', dataIndex: 'first',editor:text_editor},
{id: 'empl-col-full', width:30, header: 'Full name', dataIndex: 'fullname',editor:text_editor}
]
});
if (!contentDiv) {
Ext.DomHelper.append(Ext.getBody(), {tag:'div',id:'contentDiv'});
employees_grid.render('contentDiv');
}else {
contentDiv.remove();
Ext.DomHelper.append(Ext.getBody(), {tag:'div',id:'contentDiv'});
employees_grid.render('contentDiv');
}
}
function show_phones() {
var contentDiv = Ext.get('contentDiv');
var phones_grid = new Ext.grid.EditorGridPanel({
autoExpandColumn: 'phon-col-numb',
frame:false,
title: 'Phones',
height:300,
width:330,
store: phones,
tbar: [
{
text: 'Add new phone',
iconCls:'add',
handler: function(){
var r= new phone_model ({
phone_id: 0,
phone: ''
});
phones_grid.stopEditing();
phones.insert(0,r);
phones_grid.startEditing(0,0);
}
},'-'
],
columns: [
{id: 'phon-col-id', header: 'Id', dataIndex: 'phone_id',editor:text_editor},
{id: 'phon-col-numb', width:30, header: 'Number', dataIndex: 'phone',editor:text_editor}
]
});
if (!contentDiv) {
Ext.DomHelper.append(Ext.getBody(), {tag:'div',id:'contentDiv'});
phones_grid.render('contentDiv');
}else {
contentDiv.remove();
Ext.DomHelper.append(Ext.getBody(), {tag:'div',id:'contentDiv'});
phones_grid.render('contentDiv');
}
}
var win = new Ext.Toolbar({
renderTo: document.body,
items: [
{
text: 'Employees',
handler: show_employees
},'-',
{
text: 'Phones',
handler: show_phones
}
]
});
win.show();
Probbably it will be too easy for most of you, but please do not hesitate to respond. I am looking forward to any suggestions.