I have a form panel in http://jsfiddle.net/YGQxb/
var form = Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
items: [{
xtype: 'fieldcontainer',
fieldLabel: 'Test',
labelWidth: 50,
items: [{
xtype: 'fieldcontainer',
id: 'content',
items: [{
fieldLabel: 'Date',
xtype: 'datefield',
name: 'first',
allowBlank: false
},{
xtype: 'button',
text: 'Get position',
handler: function () {
// how to get position of items
alert('position is 1 of id:content');
}
}]
}]
}],
renderTo: Ext.getBody()
});
That has 2 items (date, button). I want to get position of date item or button item of parent has id 'content'.
Is that posible? how to do that thanks
If you are looking for parent order, http://jsfiddle.net/YGQxb/8/ it depends on where you start... You could use .up() and .down() and count until you reach the itemId you want as root parent or leaf child.
...
itemId: 'content',
...
handler: function () {
// how to get position of items
var reachedRoot = false;
var maxHops = 10;
var parent;
var cnt = 0;
while (!reachedRoot && cnt < maxHops){
parent = this.up();
cnt+=1;
if (parent.itemId == 'content') {
reachedRoot = true;
}
}
alert("Button depth from content:" + cnt);
}
...
If you are looking for index position: jsfiddle.net/YGQxb/7/
handler: function () {
// how to get position of items
var dateField = this.previousSibling();
var button = this;
var parentContainer = this.up();
alert('dateField pos: ' + parentContainer.items.keys.indexOf(dateField.id));
alert('button pos: ' + parentContainer.items.keys.indexOf(button.id));
}
If you look for XY Position... here jsfiddle.net/YGQxb/6/
You can use .up() or .down() to query parent and children ex.: .up('#content') in your case. Then use .getPosition() to get the position.
...
handler: function () {
// how to get position of items
var parent = this.up('#content');
var parentPos = parent.getPosition();
var btnPos = this.getPosition();
alert(Ext.String.format("parent Pos:{0}x{1} Button Pos: {2}x{3}",
parentPos[0],
parentPos[1],
btnPos[0],
btnPos[1])
);
}
...
You can add those itemId properties to each of your items and use getPosition() method on those items you would like to get position.
example code :
var c = new Ext.panel.Panel({ //
height: 300,
renderTo: document.body,
layout: 'auto',
items: [
{
itemId: 'p1',
title: 'Panel 1',
height: 150
},
{
itemId: 'p2',
title: 'Panel 2',
height: 150
}
]
})
p1 = c.getComponent('p1'); // not the same as Ext.getCmp()
p2 = p1.ownerCt.getComponent('p2'); // reference via a sibling
and to get position now you could use p1.getPosition()
Also your code could work like this fidle . OwnerCt points to fieldcontainer
Related
I am trying to delete a selected row in my Viewport component that extends Ext.grid.panel. The below example allows me to select rows but it is instantiated as a grid.Panel not a Viewport. Is it possible to select a specific row with a viewPort that extends grid.Panel
similar: https://fiddle.sencha.com/#view/editor&fiddle/2ech
I've had various attempts but I believe my issue is that I cannot grab the grid.
My code
var mainView = Ext.create('Ext.container.Viewport', {
//extends grid.panel
extend: 'Ext.grid.Panel',
items: [{
//xtype is used to re-use components or classes
xtype: 'grid',
store: userStore,
columns: [{
text: 'Name',
dataIndex: 'name',
flex: 1
}, {
text: 'Email Address',
dataIndex: 'email',
flex: 2
}, {
text: 'Phone Number',
dataIndex: 'phone',
flex: 2
}]
}, {
xtype: 'button',
text: 'NEW',
height: 50,
width: '33%',
handler: function () {
var win = Ext.create('innerWindow');
win.show();
}
}, {
xtype: 'button',
text: 'VIEW',
height: 50,
width: '33%',
handler: function () {
var win = Ext.create('innerWindow');
win.show();
}
}, {
xtype: 'button',
text: 'DELETE',
height: 50,
width: '33%',
handler: function () {
let selected = grid.getSelection();
//want to delete selected row
//var record = userStore.getAt(0);
userStore.remove(selected);
}
}]
});
First, give an id to your grid:
id: 'MyGrid'
Now you can reference the grid:
handler: function () {
var grid = Ext.getCmp("MyGrid");
var store = grid.getStore();
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
I am new in ExtJS and I need your help to create a Grid with two scales, the first one in the first column of the grid(Financial, Technical..), and the second one in the first row of the grid(J+1, J+2..), and for every column/row index there's a combobox to make assessments, like this :
show image
Can anyone help me please ?
Thank you very much.
Ext.onReady(function () {
var renderer = function (val) {
var loop = ['Barney','Fred'];
var str = '<select name="first">';
for(var i = 0; i < loop.length ; i++){
if(val === loop[i]){
str += '<option value="'+loop[i]+'" selected>'+loop[i]+'</option>';
}else{
str += '<option value="'+loop[i]+'">'+loop[i]+'</option>';
}
}
str += '</select>';
return str;
};
var rt = Ext.data.Record.create([{
name: 'id'
}, {
name: 'fullname'
}, {
name: 'first'
}]);
var myStore = new Ext.data.Store({
// explicitly create reader
reader: new Ext.data.ArrayReader({
idIndex: 0 // id for each record will be the first element
},
rt // recordType
)
});
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody(),
store: myStore,
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: true
},
columns: [{
header: '',
dataIndex: 'fullname'
}, {
header: '1',
dataIndex: 'first',
renderer : renderer
}, {
header: '2',
dataIndex: 'first',
renderer : renderer
}, {
header: '3',
dataIndex: 'first',
renderer : renderer
}, {
header: '4',
dataIndex: 'first',
renderer : renderer
}]
}),
//sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
width: 600,
height: 300,
frame: true,
title: 'Framed with Row Selection and Horizontal Scrolling',
iconCls: 'icon-grid'
});
var myData = [
[1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element
[2, 'Barney Rubble', 'Barney']
];
myStore.loadData(myData);
});
Please refer fiddle.
Hope this helps.
Can anyone tell me how I can keep the position of my scroll bar when my datastore reloads? Below is the code I have for the window/grid and refresh code. Everytime refreshActions executes the scroll bar scrolls to the top of the grid:
preserveScrollonRefresh does not work in this scenario
View
Ext.define('Tool.view.ActionView',{
extend: 'Ext.window.Window',
xtype: 'toolactions',
requires:[
'Tool.view.ActionController'
],
controller: 'actions',
viewModel: {},
layout: { type: 'border' },
closeAction: 'hide',
title: 'Actions',
store: 'Task',
width: 1500,
height: 800,
items: [{
id: 'ChangeLog',
xtype: 'grid',
selType: 'rowmodel',
split: true,
title: 'Log',
region: 'south',
width: 600,
height: 300,
bind: {store: '{tasks}'},
columns: {
defaults: {
width: 175
},
items: [
{ text: 'Script Command', dataIndex: 'command_script', flex: 1},
{ text: 'Output', dataIndex: 'command_output', width: 250, flex: 1 },
{ text: 'Status', dataIndex: 'state', width: 250, flex: 1 }]
},
bbar: ['->',{
xtype: 'button',
text: 'Refresh',
listeners: {
click: 'refreshActions'
}
}
]
}]
Refresh Code
refreshActions: function() {
var me = this;
this.currentRecord.tasks().load(function(records, operation, success) {
if(!operation.wasSuccessful()) {
var message = "Failed to load data from server.";
if(operation.hasException())
message = message + " " + operation.getError();
var app = Tool.getApplication();
app.toast(message,'error');
}
else {
me.configureButtons();
me.configureAutoRefresh();
}
});
}
Detect for Auto Refresh
configureAutoRefresh: function() {
var autoRefresh = false;
var maxId = this.getMaximumId(this.currentRecord.tasks());
var maxRecord = this.currentRecord.tasks().getById(maxId);
if(maxRecord.data.state=='1' || maxRecord.data.state=='0') {
autoRefresh = true;
}
if(autoRefresh == true) {
if(this.autoRefreshTask == null) {
var me = this;
var task =
{
run: function() {
me.refreshActions();
return true;
},
interval: 2000 // 2 seconds
};
this.autoRefreshTask = Ext.TaskManager.start(task);
}
}
else if(this.autoRefreshTask != null) {
Ext.TaskManager.stop(this.autoRefreshTask);
this.autoRefreshTask = null;
}
}
As I see it you have 2 options that not necessarily exclude each other:
If a grid row is selected:
Before the store reload get the selected record using getSelection() method and after the action is complete use the ensureVisible( record, [options] ) method to scroll that record into view.
If no row is selected:
Before the store reload get the current scroll position (I assume in your case is X) using the getScrollX() method and after the action is complete use setScrollX(x, [animate]) to get back to the previous scroll position.
I have window with button enter and few fields i need to get the data out of the form and there is method on button :
enter: function (button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
record.set(values);
win.close();
this.getUsersStore().sync();
Here record is undefined. What i do wrong?
////////////////////////////////////////////////////////////////////
Here the form:
Ext.define('ExtMVC.view.portlet.Login', {
extend: 'Ext.window.Window',
alias: 'widget.login',
layout: 'fit',
title: 'LogIn',
width: 300,
height: 150,
autoShow: true,
store: 'LoginModels',
initComponent: function () {
this.items = [
{
xtype: 'form',
items: [
{
xtype: 'textfield',
name: 'Name',
fieldLabel: 'Name',
style: { 'margin': '10px' },
},
{
xtype: 'textfield',
name: 'Password',
fieldLabel: 'Password',
style: { 'margin': '10px' },
}
]
}
];
this.buttons = [
{
text: 'Enter',
action: 'enter',
//handler: this.enter
},
{
text: 'Cancel',
scope: this,
handler: this.close
},
{
text: 'Sing in',
scope: this,
handler: this.close
}
];
this.callParent(arguments);
}
});
try to replace with this code
values=form.getForm().getValues();
Please go through the ext doc as it clearly says:
getRecord( ) : Ext.data.Model :
Returns the currently loaded Ext.data.Model instance if one was loaded via loadRecord.
And in case of your example I dont see any code that loads your form panel using loadRecord().
enter: function (button) {
var win = button.up('window'),
form = win.down('form'),
//record = form.getRecord(), /*not required here*/
record = this.getUsersStore().findRecord('id', 1) /*if you know id or some thing which field is know*/
values = form.getValues();
record.set(values);
win.close();
this.getUsersStore().sync();
You have to load form using form.loadRecord() before fetching it through form.getRecord(), otherwise form.getRecord() returns undefined.
I have created 3 panels,2 buttons(Prev,next) in Extjs and added to viewport.
At a time only one panel should visible (by default first panel).
On click of next button it should display next panel,then if i click on "prev" button it should display the previous panel.
Now i have wrote a code for panels and its working as ,panels are not navigating to left and right properly.
Here is my code :
Ext.application({
name: 'HelloExt',
requires: [
'Ext.util.Point'
],
launch: function() {
var button =Ext.create('Ext.Button', {
text: 'Toggle Containers',
handler: function () {
if (this.clickCount==1) {
containerPanel1.getEl().scrollRight;
containerPanel2.getEl().slideIn('t', 'toggle');
this.clickCount=2;
} else {
this.clickCount = 1;
containerPanel1.getEl().slideIn('t', 'toggle');
containerPanel2.getEl().scrollLeft;
}
},
renderTo: Ext.getBody()
});
var containerPanel1 = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
draggable: {
insertProxy: false,
startDrag: function(e) {
var el = Ext.get(this.getEl());
el.dd = new Ext.dd.DDProxy(el.dom.id, 'group');
this.x = el.getLeft(true);
this.y = el.getTop(true);
},
afterDrag: function(e) {
this.x = el.getLeft(true);
this.y = el.getTop(true);
this.fireEvent('itemdrag', this);
}
},
width:400,
height:550,
layout: 'column',
bodyStyle:{'background-color':'blue'},
margin:'30 0 0 20',
suspendLayout: true ,
defaults :{
xtype: 'panel',
margin:'30 0 0 0',
height: 450,
columnWidth: 0.2
},
items: [
{
html: 'Child Panel 1',
},
{
html: 'Child Panel 2',
},
{
html: 'Child Panel 3',
},
{
html: 'Child Panel 4',
},
{
html: 'Child Panel 5',
}
]
});
containerPanel1.draggable;
var containerPanel2 = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
draggable: {
insertProxy: false,
startDrag: function(e) {
var el = Ext.get(this.getEl());
el.dd = new Ext.dd.DDProxy(el.dom.id, 'group');
this.x = el.getLeft(true);
this.y = el.getTop(true);
},
afterDrag: function(e) {
this.x = el.getLeft(true);
this.y = el.getTop(true);
this.fireEvent('itemdrag', this);
}
},
width:400,
height:550,
layout: 'column',
bodyStyle:{'background-color':'green'},
margin:'30 0 0 20',
suspendLayout: true ,
defaults :{
xtype: 'panel',
margin:'30 0 0 0',
height: 300,
columnWidth: 0.2
},
items: [
{
html: 'Child Panel 1',
},
{
html: 'Child Panel 2',
},
{
html: 'Child Panel 3',
},
{
html: 'Child Panel 4',
},
{
html: 'Child Panel 5',
}
]
});
containerPanel2.draggable;
containerPanel2.getEl().hide();
Ext.create('Ext.container.Viewport', {
layout: 'column',
items: [containerPanel1,containerPanel2,button]
});
}
});
Please help me..Thanks
I was just building a similar project, so here's an example snippet you could use. Notice that you can change the amount and order of panels and the code will still work. The click handler simply looks for the visible panel first, and then depending on the direction attempts to either go forward or backward.
Ext.define('MyApp.view.MyViewport1', {
extend: 'Ext.container.Viewport',
id: 'switchPanels',
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'panel',
height: 100,
html: 'this is panel 1',
title: 'My Panel A'
},
{
xtype: 'panel',
height: 100,
hidden: true,
html: 'this is panel 2',
title: 'My Panel B'
},
{
xtype: 'panel',
height: 100,
hidden: true,
html: 'this is panel 3',
title: 'My Panel C'
},
{
xtype: 'container',
switchPanel: function(forward) {
var p = Ext.ComponentQuery.query('panel(true){isVisible()}')[0]; // visible panel
var n = forward ? p.nextSibling('panel(true)') : p.previousSibling('panel(true)'); // closest sibling
if (n) { // don't let go past the last one
p.hide();
n.show();
}
else {
console.log("can't go past the " + (forward ? 'end' : 'beginning'));
}
},
id: 'buttons',
items: [
{
xtype: 'button',
handler: function(button, event) {
button.up().switchPanel(false);
},
text: 'Prev'
},
{
xtype: 'button',
handler: function(button, event) {
button.up().switchPanel(true);
},
text: 'Next'
}
]
}
]
});
me.callParent(arguments);
}
});
You need to use card(Wizard) layout for this. please refer simple sample example below.
Im sure this will help you to resolve your problem.
var active = 0;
var main = Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
width: 200,
height: 200,
layout: 'card',
tbar: [{
text: 'Next',
handler: function(){
var layout = main.getLayout();
++active;
layout.setActiveItem(active);
active = main.items.indexOf(layout.getActiveItem());
}
}],
items: [{
title: 'P1'
}, {
title: 'P2'
}, {
title: 'P3',
listeners: {
beforeactivate: function(){
return false;
}
}
}]
});
Please refer card(wizard) layout in the below link.
http://docs.sencha.com/extjs/4.2.0/#!/example/layout-browser/layout-browser.html
Thanks