I have a big problem with the Ext.dataview.List deselect method, it doesn't exist in this version, I'm working in a migration from 6.0.1 to 6.5.3 and all lists that calls the deselect method doesn't work currently.
Regards.
You need to use dataView.getSelectable().deselect(record); method.
In this FIDDLE, I have created a demo using dataview. I hope this will help you to achieve your requirement.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create({
xtype: 'panel',
tittle: 'DeSELECT RECORD',
fullscreen: true,
layout: 'vbox',
items: [{
xtype: 'button',
text: 'De-select selected record',
handler: function (btn) {
var dataView = btn.up('panel').down('dataview');
//If you have single selction then you just need to get {dataView.getSelection()}
//it will return single record.
dataView.getSelectable().deselect(dataView.getSelection());
//If you have multiple selection then you need to get {dataView.getSelections()}
// it will return all selected record
// need to loop to deselect every record
// dataView.getSelections().forEach(r => {
// dataView.getSelectable().deselect(r);
// });
}
}, {
xtype: 'dataview',
flex: 1,
// layout:'fit',
// width:'100%',
store: {
fields: ['name', 'age'],
data: [{
name: 'Peter',
age: 26
}, {
name: 'Ray',
age: 21
}, {
name: 'Egon',
age: 24
}, {
name: 'Winston',
age: 24
}]
},
itemTpl: '<div>{name} is {age} years old</div>'
}]
});
}
});
CSS
<style>
.x-dataview-item {
background-color: #ccc;
color: #FFF;
padding: 10px;
font-weight: bolder;
border-bottom: 1px solid #fff;
}
.x-dataview-item.x-selected{
background-color: #5c5c;
}
</style>
The correct method is to interact with the selectable. Fiddle:
Ext.application({
name: 'Fiddle',
launch: function () {
var dv = Ext.Viewport.add([{
xtype: 'dataview',
store: {
data: [{
name: 'Peter'
}, {
name: 'Ray'
}, {
name: 'Egon'
}, {
name: 'Winston'
}]
},
itemTpl: '{name}'
}, {
docked: 'top',
xtype: 'button',
text: 'Deselect first',
handler: function (btn) {
dv.getSelectable().deselect(dv.getStore().first());
}
}])[0];
dv.getSelectable().select(0);
}
});
Related
How to get the record of selected grid row in EXTJS modern toolkit, but when listeners uses delegated event?
I added appropriate listener in grid component, and that provides information about selected div, but this is comppletelly useless unless the onformation which record is clicked in known.
In classic tolkit there is something like 'record,data' and 'recordIndex', but I don't see anything similar on modern toolkit.
var store = Ext.create('Ext.data.Store', {
fields: [{
name: 'name1',
type: 'string'
}, {
name: 'name2',
type: 'string'
}],
data: [{
name1: 'John',
name2: 'Smith',
}],
});
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
height: 700,
items: [{
xtype: 'grid',
cls: 'grid',
//rowLines: false,
height: 700,
store: store,
columns: [{
text: '',
xtype: 'templatecolumn',
cell: {
encodeHtml: false
},
tpl: new Ext.XTemplate(
'<div class="grid-box">',
'<div class="name">{name1}</div>',
'<div class="name">{name2}</div>',
'</div>',
),
flex: 1
}],
listeners: {
click: {
element: 'element',
delegate: 'div.grid-box',
fn: function (a, b, c) {
debugger;
console.log(a, b, c);
}
}
}
}]
});
CSS
.grid .x-show-selection > .x-listitem.x-selected {
background-color: pink;
}
.grid .x-show-selection > .x-listitem.x-selected {
background-color: pink;
}
.grid .x-listitem {
background-color: #a9f1ad;
}
.grid-box {
background: #fff;
border: 1px solid #cbd2d6;
padding: 15px;
height: 100%;
}
.grid .x-gridcell-body-el {
padding: 5px 0px 5px 10px;
}
.name {
font-size:22px;
line-height:22px;
}
Store recordId in wrapper div attribute and read it in tap handler:
var store = Ext.create('Ext.data.Store', {
fields: [{
name: 'name1',
type: 'string'
}, {
name: 'name2',
type: 'string'
}],
data: [{
name1: 'John',
name2: 'Smith',
}, {
name1: 'Muster',
name2: 'Mustermann',
}],
});
Ext.create('Ext.Container', {
renderTo: Ext.getBody(),
height: 700,
items: [{
xtype: 'grid',
cls: 'grid',
//rowLines: false,
height: 700,
store: store,
columns: [{
text: '',
xtype: 'templatecolumn',
cell: {
encodeHtml: false
},
tpl: new Ext.XTemplate(
'<div class="grid-box" recordId={id}>', // Store recordId in div attribute
'<div class="name">{name1}</div>',
'<div class="name">{name2}</div>',
'</div>',
),
flex: 1
}],
listeners: {
click: {
element: 'element',
delegate: 'div.grid-box',
fn: function (a, b, c) {
var grid = Ext.getCmp(this.id),
store = grid.getStore(),
record = store.getById(b.getAttribute('recordId'))
console.log(record.getData());
}
}
}
}]
});
I'm new using Ext JS and I need to add a button in my Viewport.
I have tried adding it as an item but it doesn't work when I click on it:
items: [ {
xtype: 'datepicker',
width: 211
},
{
xtype: 'datepicker',
width: 211
},
{
xtype: 'button',
text: 'Search',
width: 211
},
],
So then, in the official documentation I have found another way to add it:
Ext.create('Ext.Button', {
text : 'Button',
renderTo : Ext.getBody(),
listeners: {
click: function() {
// this == the button, as we are in the local scope
this.setText('I was clicked!');
},
mouseover: function() {
// set a new config which says we moused over, if not already set
if (!this.mousedOver) {
this.mousedOver = true;
alert('You moused over a button!\n\nI wont do this again.');
}
}
}
});
But I want it in the west region I defined in my Viewport and I have no idea about how to achieve this since I'm completely new at Ext JS.
My code:
function init() {
Ext.application({
name: 'MyApp',
launch: function() {
Ext.create('Ext.data.Store', {
storeId:'prices',
fields:['name', 'priceNight', 'totalPrice', 'Check-in', 'Check-out'],
data:{'items':[
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
Ext.create('Ext.container.Viewport', {
layout: 'border',
items: [{
title: 'West',
region: 'west',
margins: '0 5 0 5',
flex: .3,
collapsible: true,
split: true,
titleCollapse: true,
items: [
{
xtype: 'datepicker',
width: 211
},
{
xtype: 'datepicker',
width: 211
},
{
//I want the button here.
},
],
}, {
title: 'Center',
region: 'center',
collapsible: false,
items: {
// I want to add it just there
xtype: 'grid',
store: Ext.data.StoreManager.lookup('prices'),
columns: [
],
}
}]
});
}
});
}
I would like the button here:
Any ideas?
Thank you in advance!
I have just figured out how to do it! I'm going to post here what I did so maybe it will result helpful for some people:
It's just simple as invocating it using a variable.
Button code:
var button = Ext.create('Ext.Button', {
text : 'Button',
renderTo : Ext.getBody(),
listeners: {
click: function() {
// this == the button, as we are in the local scope
this.setText('I was clicked!');
},
mouseover: function() {
// set a new config which says we moused over, if not already set
if (!this.mousedOver) {
this.mousedOver = true;
alert('You moused over a button!\n\nI wont do this again.');
}
}
}
});
In your viewport you just have to add it as an item:
...
items: [
{
items: button //button is the variable that we defined when we created the button
}
]
...
Final result:
I hope this will help someone who is having the same question as me :)
I'm keep facing with a issue to choice exact component with scope. As you'll notice below I've created 2 different functions inside gridpanel. One of those creates a Ext.MessageBox for confirm. And other function creates a Ext.window.Window depends on button click of MessageBox.
The thing here is; It should destroy related component with cancel and no buttons. Both buttons always point to gridpanel because of var me = this state and destroys the gridpanel itself.
How can I point destroy method directly to related component?
Ext.define('MyApp.FooGrid', {
extend: 'Ext.grid.Panel',
reference: 'fooGrid',
getGridMenu: function () {
// Here is the 'Update' function; with right-click user being able to see `contextmenu`
var me = this;
var ret = [
{
text: 'Update',
listeners: {
click: me.onUpdate,
scope: me
}
}
];
return me.callParent().concat(ret);
},
onUpdate: function () {
var me = this,
gridRec = this.getSelectionModel().getSelection(); // Here being able to retrieve row data.
Ext.MessageBox.confirm(translations.confirm, translations.confirmChange, me.change, me);
return gridRec;
},
change: function (button) {
var me = this;
var selectedRec = me.onUpdate();
var selectedRecEmail = selectedRec[0].data.email; //Retrieves selected record's email with right-click action
if (button === "yes") {
return new Ext.window.Window({
alias: 'updateWin',
autoShow: true,
title: translations.update,
modal: true,
width: 350,
height: 200,
items: [
{
xtype: 'container',
height: 10
},
{
xtype: 'textfield',
width: 300,
readOnly: true,
value: selectedRecEmail //Display selected record email
},
{
xtype: 'textfield',
width: 300,
fieldLabel: translations.newPassword
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
text: translations.cancel,
listeners: {
click: function () {
me.destroy(); // Here is the bug: When user clicks on this button; should destroy current window but it destroys 'gridpanel' itself
}
}
},
{
xtype: 'button',
text: translations.save,
listeners: {
click: function () {
console.log("I'll save you!");
}
}
}
]
}
]
});
} else {
console.log('this is no!');
me.destroy(); // Another bug raises through here: If user will click on No then 'messagebox' should destroy. This one is destroys the gridpanel as well.
}
}
});
How can I point destroy method directly to related component?
Firstly on confirmation box button's(No) click, you don't need to destroy it will automatically hide the box whenever you click into No.
And for update window instead of using me.destroy() you need to use directly button.up('window').destroy() so it will only destroy your update window not the grid.
And also you don't need to again call me.onUpdate() inside of change function otherwise it will again show the confirmation box. You can directly get selected record on the change function like this me.getSelection().
In this Fiddle, I have created a demo using your code and I have put my efforts to get result.
CODE SNIPPET
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.data.Store', {
storeId: 'demostore',
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Demo GRID',
store: 'demostore',
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
listeners: {
itemcontextmenu: function (grid, record, item, index, e, eOpts) {
e.stopEvent();
grid.up('grid').getGridMenu().showAt(e.getXY());
}
},
renderTo: Ext.getBody(),
getGridMenu: function () {
var me = this;
if (!me.contextMenu) {
me.contextMenu = Ext.create('Ext.menu.Menu', {
width: 200,
items: [{
text: 'Update',
handler: me.onUpdate,
scope: me
}]
});
}
return me.contextMenu;
},
onUpdate: function () {
var me = this;
Ext.MessageBox.confirm('Confirmation ', 'Are your sure ?', me.change, me);
},
change: function (button) {
var me = this,
selectedRecEmail = me.getSelection()[0].data.email; //Retrieves selected record's email with right-click action
if (button === "yes") {
return new Ext.window.Window({
autoShow: true,
title: 'Update',
modal: true,
width: 350,
height: 200,
items: [{
xtype: 'tbspacer',
height: 10
}, {
xtype: 'textfield',
width: 300,
readOnly: true,
value: selectedRecEmail //Display selected record email
}, {
xtype: 'textfield',
inputType:'password',
width: 300,
fieldLabel: 'New Password'
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [{
xtype: 'tbfill'
}, {
xtype: 'button',
text: 'cancel',
listeners: {
click: function (btn) {
btn.up('window').destroy(); // Here is the bug: When user clicks on this button; should destroy current window but it destroys 'gridpanel' itself
}
}
}, {
xtype: 'button',
text: 'save',
listeners: {
click: function () {
console.log("I'll save you!");
}
}
}]
}]
});
}
}
});
}
});
I have a tabpanel consisting of 3 tabs. 3rd tab shows external vendor contents. I also have a text box and enter button. based on value entered in text box, I need to refresh contents of 3rd tab.
{//second tab end, third tab starts
id: 'test',
title: "Test3",
layout: "fit",
html: iframebody,
listeners: {
'render': function(){
var e = document.getElementsByTagName("head")[0];
var s = document.createElement("script");
s.type = "text/javascript";
s.src = msaJs;
e.appendChild(s);
},
'show': function(panel){
//var tickerValue1 = Ext.getCmp('tabpanel').getActiveTab().html;
theurl = 'http://example.com?ticker=' +ticker+';
iframebody = '<iframe width=100% height=100% src='+theurl+'></iframe>';
var tab1= Ext.getCmp('tabpanel').setActiveTab(2);
alert(Ext.getCmp('tabpanel').getActiveTab().html);
Ext.getCmp('tabpanel').getActiveTab().html=iframebody;
alert(Ext.getCmp('tabpanel').getActiveTab().html);
Ext.getCmp('tabpanel').getActiveTab().getUpdater().refresh();
},//show listener ended
Now, when I press enter, tab doesnt get refreshed with new ticker eventhough the alert message shows updated html for the tab. Any help would be highly appreciated.
If you are using same origin in iframe then you can use directly like below :-
iframe.contentWindow.location.reload();
For ExtJS 3.x, you need to use iframe.src for refresh after getting iframe dom. If you have provided some id to iframe then you can access like below
Ext.get('iframe')//example id:'iframe'
In this FIDDLE, I have created a demo using TabPanel and KeyNav. I hope this will help you or guide you to achieve your requirement.
Code Snippet ExtJS 3.X
Ext.onReady(function () {
var tabs = new Ext.TabPanel({
height: window.innerHeight,
fullscreen: true,
renderTo: document.body,
activeTab:0,
items: [{
title: 'Tab 1',
html: 'tab1'
}, {
title: 'Tab 2',
html: 'tab2'
}, {
title: 'Tab 3',
itemId: 'tab3',
padding: '20 20 0 20',
items: [new Ext.BoxComponent({
id: 'iframe',
height: '100%',
width: '100%',
autoEl: {
tag: 'iframe',
src: 'https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=eiffel+tower&aq=&sll=41.228249,-80.661621&sspn=11.149099,23.269043&ie=UTF8&hq=&hnear=Eiffel+Tower,+5+Avenue+Anatole+France,+75007+Paris,+%C3%8Ele-de-France,+France&t=h&ll=48.858186,2.294512&spn=0.002471,0.00456&z=17&output=embed',
style: 'width: 100%; border: none'
}
})],
bbar: [{
text: 'Refresh UxIframe',
id: 'refresh',
handler: function () {
Ext.get('iframe').dom.src += '';
}
}],
listeners: {
afterrender: function (panel) {
panel.keynav = new Ext.KeyNav(Ext.getBody(), {
scope: panel,
enter: function () {
Ext.getCmp('refresh').handler()
}
});
}
}
}]
});
});
Here In this FIDDLE I have created same demo with 6.5 version. So for new version it will also help you/other folks. In newer versions here component uxiframe and uxiframe have load() method. So we can use this and refresh the iframe.
Code Snippet ExtJS 6.X
Ext.application({
name: 'Fiddle',
requires: ['Ext.ux.IFrame'],
launch: function () {
Ext.create('Ext.tab.Panel', {
height: window.innerHeight,
fullscreen: true,
renderTo: document.body,
activeTab:0,
items: [{
title: 'Tab 1',
html: 'Tab 1'
}, {
title: 'Tab 2',
html: 'Tab 2'
}, {
title: 'Tab 3',
itemId: 'tab3',
padding: '20 20 0 20',
items: {
xtype: 'uxiframe',
height: '100%',
width: '100%',
src: 'https://docs.sencha.com/extjs/6.5.2/index.html'
},
bbar: [{
text: 'Refresh UxIframe',
itemId: 'refresh',
handler: function () {
var uxiframe = this.up('#tab3').down('uxiframe');
uxiframe.load(uxiframe.src);
}
}],
listeners: {
afterrender: function (panel) {
panel.keynav = Ext.create('Ext.util.KeyNav', {
target: Ext.getBody(),
scope: panel,
enter: function () {
this.down('#refresh').fireHandler()
}
});
panel.focus(true);
}
}
}]
});
}
});
I am trying to add Checkboxes for a Rally Report version 2.00p2.
I defined severals place holders for the filter (releaseFilter and stateFilter)
and Adding the checkboxes at the body of the onReady function at the end.
However, Instead of 5 different checkbox I get 1 and on top of the Release filter.
Sorry But I couldn't add an Image.
Rally.onReady(function() {
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
autoScroll: 'true',
items: [
{
xtype: 'container',
itemId: 'releaseFilter',
style: {
margin: '5px'
}
},
{
xtype: 'container',
itemId: 'stateFilter',
style: {
margin: '5px'
}
},
{
xtype: 'container',
itemId: 'grid',
style: {
margin: '10px',
}
},
// SOME CODE
],
launch: function() {
Rally.data.ModelFactory.getModel({
type: 'UserStory',
success: function(model) {
this.grid = this.add({
xtype: 'rallygrid',
model: model,
columnCfgs: [
'FormattedID',
'Release',
'Iteration',
'PlanEstimate',
'PlanDevEstDays',
'PlanQAEstDays'
],
storeConfig: {
filters: [
{
property: 'ScheduleState',
operator: '=',
value: 'Accepted'
}
]
}
});
this.down('#releaseFilter').add(
{
xtype: 'rallyreleasecombobox'
}
);
this.down('#stateFilter').add([{
xtype: 'menucheckitem',
text: 'Backlog',
floating: 'false'
},{
xtype: 'menucheckitem',
text: 'Defined'
},{
xtype: 'menucheckitem',
text: 'In-Progress'
},{
xtype: 'menucheckitem',
text: 'Completed'
},{
xtype: 'menucheckitem',
text: 'Accepted'
}]
);
},
scope: this
});
}
});
Rally.launchApp('CustomApp', {
name: 'Grid Example'
});
});
The original Entry in your javadoc is:
Ext.create('Ext.menu.Menu', {
width: 100,
height: 110,
floating: false, // usually you want this set to True (default)
renderTo: Ext.getBody(), // usually rendered by it's containing component
items: [{
xtype: 'menucheckitem',
text: 'select all'
},{
xtype: 'menucheckitem',
text: 'select specific',
},{
iconCls: 'add16',
text: 'icon item'
},{
text: 'regular item'
}]
});
What did I do wrong ?
Instead of using menucheckitem, use a standard Ext checkbox. Like this:
this.down('#stateFilter').add([{
xtype: 'checkbox',
fieldLabel: 'Backlog'
},
...
]);
Be sure change it from text to fieldLabel