How to solve multiple occuring text fields in ext js3? - extjs

I have a tab panel.I open a tab and a grid is shown. Then i double click a row and a window is opened. In this window i have a panel and in this panel i have 4 textfields.
Then i close window, and double click another row, window is opened and fields that in panel shown correctly like below.
label label label label
|_______| |______| |______| |______|
When i close tab and opened it again and click row to open window, window is opened but in my panel's items shown three times. I mean it looks like below :
label label label label
label label label label
label label label label
And every click rows it is increasing...
My window is ;
var win = new Ext.Window({
width: 680,
height: 250,
title: 'Details',
layout: 'border',
modal: true,
closeAction:'hide',
items: [top,grid]
});
and my panel (name is top)
var top = new Ext.FormPanel({
labelAlign: 'top',
region : 'north',
frame:true,
bodyStyle:'padding:5px 5px 0',
width: 680,
height:75,
items: [{
layout:'column',
items:[{
columnWidth:.25,
layout: 'form',
items: [{
xtype:'textfield',
id : 'date',
fieldLabel: '<font color="red" style="margin-left: 25px" ><b>date</b></font>',
labelSeparator: '',
style: 'text-align: center;',
width:120
}]
},{
columnWidth:.25,
layout: 'form',
items: [{
id : 'xxx',
xtype:'textfield',
fieldLabel: '<font color="red"style="margin-left: 25px" ><b>xxxx</b></font>',
labelSeparator: '',
style: 'text-align: center;',
width:120
}]
},{
columnWidth:.25,
layout: 'form',
items: [{
id : 'cost',
xtype:'textfield',
fieldLabel: '<font color="red"style="margin-left: 4px" ><b>cost</b></font>',
labelSeparator: '',
style: 'text-align: right;',
width:120
}]
},{
columnWidth:.25,
layout: 'form',
items: [{
id : 'price',
xtype:'textfield',
fieldLabel: '<font color="red"style="margin-left: 15px" ><b>price</b></font>',
labelSeparator: '',
style: 'text-align: right;',
width:120
}]
}]
}]
});
I try to change window's closeAction config 'hide' to 'destroy', but this time i can not open window second time if i don't close the tab.
How can i fix this problem.
Thank you very much.
var grid = new Ext.grid.GridPanel({
stripeRows: true,
frame: false,
border:false,
autoScroll: true,
loadMask: {msg : 'loading...'},
trackMouseOver:false,
store: store,
bbar: paging,
region:'center',
cm: cm,
sm: sm,
viewConfig: {enableRowBody:true,emptyText: 'empty...'},
listeners: {
celldblclick: function(){
showDetail();
}
}
});
and showDetail function is ;
var showDetail = function(){
store.baseParams = {
Id : sm.getSelected().data['ID']
};
store.load();
win.show();
var d =sm.getSelected().data['date'];
Ext.getCmp("xxx").setValue(sm.getSelected().data['xxx']);
Ext.getCmp("date").setValue(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());
Ext.getCmp("cost").setValue((sm.getSelected().data['cost']));
Ext.getCmp("price").setValue((sm.getSelected().data['price']));
};

You need to create the window on every call and destroy when close
function createWindow(){
return new Ext.Window({
width: 680,
height: 250,
title: 'Details',
layout: 'border',
modal: true,
closeAction:'destroy',
items: [top,grid]
});
}
And then call the createWindow
var showDetail = function(){
store.baseParams = {
Id : sm.getSelected().data['ID']
};
store.load();
var win = createWindow();
win.show();
var d =sm.getSelected().data['date'];
Ext.getCmp("xxx").setValue(sm.getSelected().data['xxx']);
Ext.getCmp("date").setValue(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());
Ext.getCmp("cost").setValue((sm.getSelected().data['cost']));
Ext.getCmp("price").setValue((sm.getSelected().data['price']));
};

Related

Window is not closing properly second time

I want to open a new window on click of button. On cclick on button window is opening and closing fine but second time it is not closing properly.
Here is my code
var formPanel = new Ext.FormPanel({
height: 125,
autoScroll: true,
id: 'formpanel',
defaultType: 'field',
frame: true,
title: 'CheckOut from SVN',
items: [{
fieldLabel: 'SVN Path'
}],
buttons: [{
text: 'Submit',
minWidth: 75,
handler: function() {
var urlTemp = './Export?' + '&' + fp.getForm().getValues(true);
formPanel.getForm().submit({
url: urlTemp,
method: 'Post',
success: successFn1,
timeout: 18000000,
failure: otherFn
});
}
}, {
text: 'Reset',
minWidth: 75,
handler: function() {
formPanel.getForm().reset();
}
}]
});
function buildWindow() {
var win = new Ext.Window({
id: 'newWindow',
layout: 'fit',
width: 300,
height: 200,
closeAction: 'hide',
plain: true,
stateful: false,
items: [formPanel]
});
win.show();
}
var extSVN = new Ext.Button({
text: 'Checkout from SVN',
minWidth: 75,
handler: function() {
buildWindow();
}
});
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
width: 400,
height: 300,
items: [extSVN]
});
you are using closeAction: 'hide' on your window which mean that when you close it it will not be destroyed but hidden.
The problem is that when you reopen the window you create a new one so your formPanel ends up in 2 different windows which causes the error.
You can :
remove the closeAction: 'hide', but your formPanel will also be
destroy when you close the window, so you'll have to recreate
another too
or keep the closeAction: 'hide' and only create the
windows one time
You have provided id to your form and window. And inside window you have set config closeAction: 'hide' that means whenever your press close button window is hiding.
And on again on-click of Checkout from SVN button you creating a same window and form with same id's so instead of creating of new window you can use previous window and show again.
In this FIDDLE, I have created a demo using your code and put some modifications.
CODE SNIPPET
Ext.onReady(function () {
var formPanel = new Ext.FormPanel({
height: 125,
autoScroll: true,
id: 'formpanel',
defaultType: 'field',
frame: true,
title: 'CheckOut from SVN',
items: [{
fieldLabel: 'SVN Path'
}],
buttons: [{
text: 'Submit',
minWidth: 75,
handler: function () {
var urlTemp = './Export?' + '&' + fp.getForm().getValues(true);
formPanel.getForm().submit({
url: urlTemp,
method: 'Post',
success: successFn1,
timeout: 18000000,
failure: otherFn
});
}
}, {
text: 'Reset',
minWidth: 75,
handler: function () {
formPanel.getForm().reset();
}
}]
});
function buildWindow(btn) {
if (!btn.win) {
btn.win = new Ext.Window({
layout: 'fit',
id: 'newWindow',
modal: true,
width: 300,
height: 200,
closeAction: 'hide',
plain: true,
stateful: false,
items: [formPanel]
});
}
btn.win.show();
}
var extSVN = new Ext.Button({
text: 'Checkout from SVN',
minWidth: 75,
handler: buildWindow
});
new Ext.Panel({
title: 'SVN Chekcout',
renderTo: Ext.getBody(),
width: 200,
height: 130,
items: [extSVN],
renderTo: Ext.getBody()
});
});

how set selected row in checkbox grid panel extjs depends textfield value

i have a grid panel and i want checked the row same as the value of text field.
anyone can help me.?
this is my code:
var check = new Ext.selection.CheckboxModel({
checkOnly : true,
listeners: {
change: function(checkbox, value) {
}
}
});
Ext.create('Ext.form.Panel', {
renderTo: "example-grid",
bodyStyle: 'padding: 5px 5px 0 5px;',
items: [
{
xtype: 'textfield',
fieldLabel: 'Group Fields ',
value:'a',
readOnly: true,
inputId: 'group'
}]
});
var grid1 = Ext.create('Ext.grid.Panel', {
title: 'Group Fields',
id:'gridPanel',
selModel: check,
store: Ext.data.StoreManager.lookup('tes'),
columns: [{
text: 'Field',
dataIndex: 'field',
flex: 1
}],
viewConfig: {
markDirty: false
},
height: 200,
width: 200
});
my fiddle example:
http://jsfiddle.net/y0uzha/f73kx37e/1/
Looks like you just need one-way binding so I would suggest to apply a selectionchange listener to the selectionModel to set the value of the groupField. See grid1#listeners#viewready. Note: I added an id to the form panel so that you can get a handle on it.
Generally speaking you should not use the id propery on child components, so they can be reusable. It would be better practice to use a viewport or a global parent container that has an id. Also, it would be best practice to use a controller to wire all this business logic together. Enjoy!
var check = new Ext.selection.CheckboxModel({
checkOnly: true
});
Ext.create('Ext.form.Panel', {
id: 'formPanel',
renderTo: "example-grid",
bodyStyle: 'padding: 5px 5px 0 5px;',
items: [{
itemId: 'groupField',
xtype: 'textfield',
fieldLabel: 'Group Fields ',
readOnly: true,
inputId: 'group'
}]
});
var grid1 = Ext.create('Ext.grid.Panel', {
title: 'Group Fields',
id: 'gridPanel',
selModel: check,
store: Ext.data.StoreManager.lookup('tes'),
columns: [{
text: 'Field',
dataIndex: 'field',
flex: 1
}],
viewConfig: {
markDirty: false
},
listeners: {
viewready: function() {
var selModel = this.getSelectionModel();
//Bind the groupField's value to the selected records
selModel.on('selectionchange', function(selModel, selections, eOpts) {
var groupField = Ext.getCmp('formPanel').queryById('groupField'),
groupValues = Ext.pluck(Ext.pluck(selections, 'data'), 'field');
groupField.setValue(Ext.Array.sort(groupValues).toString());
});
//Initially selects the first item in the grid
selModel.selectRange(0, 0);
}
},
height: 200,
width: 200
});

Can I render a Ext.FormPanel to a new Ext.window?

I want to popup a window to interact with people who want to upload a file to server. I want to render a file input form in the new window, but I can't make it run by doing follows:
var win = new Ext.Window();
var fp = new Ext.FormPanel({
renderTo: win,//I just guess that I can render this to the window I created...
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'textfield',
fieldLabel: 'Name'
},{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select an image',
fieldLabel: 'Photo',
name: 'photo-path',
buttonText: '',
buttonCfg: {
iconCls: 'upload-icon'
}
}],
buttons: [{
text: 'Save',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'file-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o){
msg('Success', 'Processed file "'+o.result.file+'" on the server');
}
});
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});
win.show();
As per the Ext JS documentation about the renderTo() method:
"Do not use this option if the Component is to be a child item of a Container. It is the responsibility of the Container's layout manager to render and manage its child items."
So what you need to do is:
Create the formPanel without the renderTo option
Create your window and specify the formPanel as an item of the window.
var win = new Ext.Window({
//You can specify other properties like height, width etc here as well
items: [fp]
});
You can refer to a working fiddle on this link:
http://jsfiddle.net/prashant_11235/2tgAQ/

How can I change percentage of the viewport in browser?

My viewport fits all browser but I want this to fit only 80% of browser's width. How can I do it?
This is my code below maybe you want to see it.
This is my viewport code:
var view = new Ext.Viewport({
layout: 'border',
autoScroll: true,
border: true,
items:[header,menuBar
,{
region: 'south',
collapsible: false,
padding: '25 25 25 25' ,
html:'Sanguis Team 2012',
border: true,
height: 100
},content
]
});
Ext.onReady(function(){
//var topHTML = '<img style="margin-left: 5px" src="Google_maps_logo.png" alt="logo" height="60" width="380">';
//Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
Ext.QuickTips.init();
var item1 = new Ext.Panel({
title: 'Kan Bağışı',
collapsible : true,
collapsed: true,
padding: '5 5 5 5' ,
html: 'Nerede Kan verebilirim?<br/>' +
'Kan Bağışlama Süreci'
});
var item2 = new Ext.Panel({
title: 'Kan Hakkında',
collapsed: true,
padding: '5 5 5 5' ,
collapsible : true,
html: 'Kanın Yapısı ve Görevleri Nelerdir?<br/>' +
'Kan Bağışlarım Nerede kullanılıyor<br/>'+
'Kan Grupları Hakkında Bilgiler<br/>'+
'Kana Yapılan Testler<br/>'+
'Dünya ve Türkiyede Kan Bağışı'
});
var item3 = new Ext.Panel({
title: '<a style="color: #FFFFFF;" href="#">Sıkça Sorulan Sorular</a>',
collapsible :false,
titleCollapse: false
});
var item4 = new Ext.Panel({
title: 'Site Kullanımı',
collapsed: true,
padding: '5 5 5 5' ,
collapsible : true,
html: 'Site Nasıl Çalışmaktadır<br/>' +
'Kan İsteğinde Nasıl Bulunabilirim?<br/>'
});
var item5 = new Ext.Panel({
padding: '5 5 5 5' ,
title: 'Kullanıcı Girişi',
bodyStyle : 'padding : 10px',
layout : 'form',
items: [
{
xtype: 'field',
fieldLabel: 'E-posta',
width: 100
},{
xtype: 'field',
fieldLabel: 'Şifre',
inputType:'password',
width: 100
},
{
xtype: 'button',
text: 'Giriş',
style: {
marginLeft: '170px'
},
align: 'right',
handler : function(btn){
Ext.MessageBox.alert('','kontrol yapılacak!!');
}
},
{
border : false,
html:'Şifremi Unuttum'
}
]
});
var item6 =new Ext.Panel({
border: false,
html: '<img src="../images/kaydol.jpg" />'
});
var menuBar = new Ext.Panel({
//layout: 'accordion',
autoScroll: true,
defaults: {autoScroll: true},
region: 'west',
width: 310,
defaults: {
hideCollapseTool : false,
//border: true
},
layoutConfig: {
// titleCollapse: false,
animate: true,
// activeOnTop: true,
autoScroll: true
},
margins:'5 0 5 5',
split:false,
items: [item1, item2, item4, item3, item5,item6]
});
var content = new Ext.Panel({
region: 'center',
autoScroll: true,
margins:'5 5 5 0',
layoutConfig : {
align : 'stretch'
},
html:'Ajax content will come here'
});
var header=new Ext.Panel({
renderTo: document.body,
layout: 'fit',
region: 'north',
html: '<p align="center"><img src="../images/banner.jpg" align="middle"/></p>',
height:150,
tbar: [
{
text: '<b>Ana Sayfa</b>',
iconCls: 'bmenu',
handler: function(){ alert('blah'); }
},
{
text: '<b>Hakkımızda</b>',
iconCls: 'bmenu',
handler: function(){ alert('blah'); }
},
{
text: '<b>Duyurular</b>',
iconCls: 'bmenu',
handler: function(){
}
},
{
text: '<b>İletişim</b>',
iconCls: 'bmenu', // <-- icon
handler: function(){ alert('blah'); }
}]
});
var view = new Ext.Viewport({
layout: 'border',
autoScroll: true,
border: true,
items:[header,menuBar
,{
region: 'south',
collapsible: false,
padding: '25 25 25 25' ,
html:'<br/><br/><p align="center"><b>Sanguis Team 2012</b></p>',
border: true,
height: 100
},content
]
});
/*var templates = new Ext.Window({
width:900,
height:700,
id:'Templates',
resizable:false,
//layout:'border',
//border:true,
closable:false,
title:'Plantillas',
items:view
});
templates.show();*/
// view.render('anasayfa');
});
There is no maxwidth property on viewport, as viewport is always the size of the window.
This works:
use a viewport, set its layout to anchor
add a container to viewport
set its anchor property to '80% 100%'
put whatever you want inside the container. you can give the container border layout if you want

ExtJS TreeGrid problem

If I run the code below in a browser I get an error display of my interface. The problem is the presence of two vertical scrollbars that are visible with both IE than with FF.
Below is an example of the code I'm using.
Ext.onReady(function() {
Ext.QuickTips.init();
var tree = new Ext.ux.tree.TreeGrid({
title: 'Core Team Projects',
enableDD: true,
defaultSortable: false,
enableSort: false,
autoScroll: true,
columns:[
{
header: 'Task',
dataIndex: 'task',
width: 230
},{
header: 'Duration',
width: 100,
dataIndex: 'duration',
align: 'center',
sortType: 'asFloat',
tpl: new Ext.XTemplate('{duration:this.formatHours}', {
formatHours: function(v) {
if(v < 1) {
return Math.round(v * 60) + ' mins';
} else if (Math.floor(v) !== v) {
var min = v - Math.floor(v);
return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm';
} else {
return v + ' hour' + (v === 1 ? '' : 's');
}
}
})
},{
header: 'Assigned To',
width: 150,
dataIndex: 'user'
},{
header: 'Test',
width: 150,
dataIndex: '',
tpl: new Ext.XTemplate(
'test'
)
}],
dataUrl: '/QgenQueryBuilder/testtreegrid/treegrid-data.json.asp'
});
var mainQueryPanel = new Ext.Panel({
id:'mainQueryPanel',
region: 'center',
layout:'fit',
margins:'0 0 0 0',
title:'Workspace',
header:true,
border:true,
draggable:false,
collapsible:false,
collapsed:false,
autoScroll:true,
hidden: false,
items:[tree]
});
var mainDataPanel = new Ext.Panel({
id:'mainDataPanel',
activeItem: 0,
region: 'south',
layout: 'card',
title:'Risultato interrogazione',
margins:'0 0 0 0',
height:290,
header:true,
border:true,
draggable:false,
collapsible:true,
collapsed:false,
autoScroll:false,
hidden: false,
split:true
});
var mainCenterPanel = new Ext.Panel({
xtype: 'panel',
id: 'mainCenterPanel',
layout: 'border',
region: 'center',
autoScroll: false,
margins: '2 0 5 5',
items:[mainQueryPanel,mainDataPanel]
});
var mainViewport =new Ext.Viewport({
layout: 'border',
//title: 'Ext Layout Browser',
items: [{
id: 'content-panel',
region: 'center', // this is what makes this panel into a region within the containing layout
layout: 'card',
margins: '2 5 5 0',
activeItem: 0,
border: false,
disabled: false,
items: [mainCenterPanel]
}]
});
});
I have no idea how to fix this error.
Any help is appreciated.
Thank you all.
Even though its not a descriptive and thoroughly explaining answer, I haven't set the autoScroll (autoScroll: true) on the TreeGrid I use. But it seems like I still get the scrollbars if the contents exceeds the visible area of its container.
Try setting all the autoScroll: true to autoScroll: false except new Ext.ux.tree.TreeGrid({
I've had this same problem with this component, it roots from treepanel not working well with border layouts. I suggest putting the tree in a wrapper panel, and have it stretch layout on wraper panel. Then set the wrapper panel in your items.

Resources