How to get record from delegated event in EXTJS? - extjs

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());
}
}
}
}]
});

Related

deselect list method in ExtJS 6.5.3

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);
}
});

Extjs 5 - Link my grid to the Viewmodel

I manage to put the datas I need in a modelView
Controller.js
init: function ()
{
var me = this;
this.mainView = this.getView().add(Ext.create('Tsi.app.tsp_use.details.MainView'));
var customer_id = this.view.customer_id;
var transaction_id = this.view.transaction_id;
this.mainView.on('afterrender', function () {
//Recherche des infos de la transaction
Ext.Ajax.request({
url: '/app/tspuse/detail',
params:
{
customer_id: customer_id,
transaction_id: transaction_id
},
success: function (response)
{
//Passer de l'item "page de chargement" à l'item suivant ici (1)
me.mainView.getLayout().setActiveItem(1);
//response.data tab clef => $valeur
me.mainView.getViewModel().setData(response.data);
console.log('hello : ', response.data);
console.log('hello 2: ', me.mainView.getViewModel());
console.log('hello 3: ', me.mainView.getViewModel().data.vouchers_detail);
}
});
});
},
Here are the datas in the console :
console datas
But I don't know how to bind them to my grind in the third tab of my mainView (see comments) :
Ext.define('Tsi.app.tsp_use.details.MainView', {
extend: 'Tsi.os.view.BaseAppView',
bodyCls: 'DPEW_body_detail',
layout: 'card',
viewModel: {
data: {}
},
items: [{
xtype: 'container',
cls: 'directpayment_detail_help',
layout: 'center',
html: '<p>' + 'directpayment_transaction.wait'._() + '</p>'
}, {
border: false,
xtype: 'tabpanel',
buttonAlign: 'left',
titleAlign: 'left',
plain: true,
tabPosition: 'left',
tabRotation: 0,
defaults: {
border: false,
buttonAlign: 'left',
titleAlign: 'left'
},
listeners: {
tabchange: 'onTabChange'
},
items: [
/**
* FIRST TAB
*/
{
icon: '/img/icons/16/man.png',
bodyStyle: 'background: url(/img/icons/256/Search-Male-User_alpha.png) no-repeat bottom right',
xtype: 'panel',
title: 'directpayment_transaction.tab_user'._(),
tbar: [
'->',
{
xtype: 'container',
text: 'directpayment_transaction.customer.head_text'._()
},
{
icon: '/img/icons/16/text_list_bullets.png',
text: 'directpayment_transaction.customer.show_all_transaction'._(),
handler: 'customerShowAllTransactions'
},
{
icon: '/img/icons/16/Bar-chart.png',
text: 'directpayment_transaction.customer.show_chart_transaction'._(),
handler: 'customerShowStats'
},
],
layout: 'fit',
items: {
border: false,
padding: 10,
xtype: 'fieldcontainer',
labelAlign: 'top',
labelWidth: 100,
defaults: {
margin: 0,
padding: 0,
labelSeparator: '',
hideEmptyLabel: false
},
items: [{
hideLabel: true,
fieldLabel: '',
xtype: 'displayfield',
//pour la date : customer_birth_date:this.toDate -> applique la fonction toDate du Controller
bind: {
value: '{customer_first_name:htmlEncode} {customer_last_name:htmlEncode} - {customer_birth_date:htmlEncode}'
},
cls: 'directpayment_detail_group'
},
{
fieldLabel: 'directpayment_transaction.customer.address'._(),
xtype: 'displayfield',
bind: {
value: '{customer_address:htmlEncode}'
}
},
{
fieldLabel: ' ',
xtype: 'displayfield',
bind: {
value: '{customer_zipcode:htmlEncode} {customer_city:htmlEncode}'
}
},
{
fieldLabel: ' ',
xtype: 'displayfield',
bind: {
value: '{customer_country:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.customer.phone'._(),
xtype: 'displayfield',
bind: {
value: '{customer_phone:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.customer.mobile'._(),
xtype: 'displayfield',
bind: {
value: '{customer_mobile:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.customer.email'._(),
xtype: 'displayfield',
bind: {
value: '{customer_email:this.toMail}'
}
}
]
}
},
/**
* SECOND TAB
*/
{
icon: '/img/icons/16/money_euro.png',
bodyPadding: 10,
title: 'directpayment.panel_detail.tab_transaction'._(),
bodyStyle: 'background: url(/img/icons/256/shopping-basket-full_alpha.png) no-repeat bottom right',
layout: 'fit',
overflowY: 'auto',
items: {
border: false,
padding: 10,
xtype: 'fieldcontainer',
labelAlign: 'top',
labelWidth: 100,
defaults: {
margin: 0,
padding: 0,
labelSeparator: '',
labelWidth: 200,
hideEmptyLabel: false
},
items: [{
hideLabel: true,
fieldLabel: '',
xtype: 'displayfield',
bind: {
value: '{payment_status:this.renderStatus}'
},
cls: 'directpayment_detail_group'
},
{
fieldLabel: 'directpayment_transaction.transaction.date'._(),
xtype: 'displayfield',
//pour la date : transaction_dtime_creation:this.toDate -> applique la fonction toDate du Controller
bind: {
value: '{transaction_dtime:this.toDateStr}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.tids'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_tid:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.amount'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_amount:this.toMoney}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.currency'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_currency:htmlEncode}'
}
},
{
fieldLabel: 'directpayment_transaction.transaction.detail'._(),
xtype: 'displayfield',
bind: {
value: '{transaction_detail}'
}
},
{
fieldLabel: 'directpayment_v1_transaction.merchant.name'._(),
xtype: 'displayfield',
bind: {
value: '{merchant_label}'
}
},
]
}
},
/**
* THIRD TAB
*/
{
icon: '/img/icons/16/barcode-16.png',
bodyPadding: 10,
title: 'tsp_use.panel_detail.tab_vouchers.title'._(),
bodyStyle: 'background: url(/img/icons/256/shopping-basket-full_alpha.png) no-repeat bottom right',
layout: 'fit',
overflowY: 'auto',
items: {
border: false,
padding: 10,
xtype: 'grid',
labelAlign: 'top',
labelWidth: 100,
defaults: {
margin: 0,
padding: 0,
labelSeparator: '',
labelWidth: 200,
hideEmptyLabel: false
},
columns: [{
text: 'tsp_use.panel_detail.tab_vouchers.voucher_ticket_sn'._(),
dataIndex: 'voucher_ticket_sn',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.voucher_ticket_amount'._(),
dataIndex: 'voucher_ticket_amount',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.voucher_ticket_balance'._(),
dataIndex: 'voucher_ticket_balance',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_id'._(),
dataIndex: 'merchant_id',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_name'._(),
dataIndex: 'merchant_name',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_address'._(),
dataIndex: 'merchant_address',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_zipcode'._(),
dataIndex: 'merchant_zipcode',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_city'._(),
dataIndex: 'merchant_city',
flex: 1
},
{
text: 'tsp_use.panel_detail.tab_vouchers.merchant_country'._(),
dataIndex: 'merchant_country',
flex: 1
},
],
store: {
fields: [
'voucher_ticket_sn',
'voucher_ticket_amount',
'voucher_ticket_balance',
'merchant_id',
'merchant_name',
'merchant_address',
'merchant_zipcode',
'merchant_city',
'merchant_country'
],
/*
* How to access datas in viewModel ?
*
* bind:{} instead of proxy:{} ?
*
*/
proxy: {
type: 'ajax',
url: '',
pageSize: 25,
reader: {}
},
autoLoad: false
},
}
},
]
}]
});
It works for the displayfield, but I failed to bind the datas to voucher_detail to my grid.
Try it this way:
viewModel: {
data: {
arrayData: undefined
},
stores: {
storeName: {
data: '{arrayData}'
}
}
}
and then you just need to bind the store to the grid.

i try to do the Spie example in Ext JS 5 but it didnt work

Here is my code i dont know why it didnt work ..the error in the console is
[W] [Ext.Loader] Synchronously loading 'widget.polar'; consider adding Ext.require('widget.polar') above Ext.onReady Util.js?_dc=1404383474396:692
GET http://localhost/widget/polar.js?_dc=1404383480019 404 (Not Found) bootstrap.js:558
Uncaught Error: [Ext.create] Unrecognized class name / alias: widget.polar ClassManager.js?_dc=1404383474396:1405
[E] [Ext.Loader] Some requested files failed to load. Util.js?_dc=1404383474396:692
Object
Util.js?_dc=1404383474396:698
console.trace() Util.js?_dc=1404383474396:704
log Util.js?_dc=1404383474396:704
Ext.apply.raise Error.js?_dc=1404383474396:186
Ext.apply.onLoadFailure Loader.js?_dc=1404383474396:649
(anonymous function) bootstrap.js:728
Uncaught Error: [Ext.Loader] Some requested files failed to load. Error.js?_dc=1404383474396:103
im just trying to create an Spie like in the example :http://dev.sencha.com/ext/5.0.0/examples/kitchensink/?charts=true#pie-custom
Ext.define('App.view.main.Main', {
extend: 'Ext.container.Container',
requires: 'App.view.main.TabPanel',
xtype: 'app-main',
controller: 'main',
viewModel: {
type: 'main'
},
layout: {
type: 'border'
},
items: [
{
region: 'center',
xtype: 'customtabpanel'
}]
});
and input it into my TAB .... i dunno why didnt work
app/view/main/TabPanel.js
Ext.define('App.view.main.TabPanel', {
extend: 'Ext.tab.Panel',
xtype: 'customtabpanel',
requires:['App.view.main.Pie'],
ui: 'navigation',
tabPosition: 'left',
tabRotation: 0,
tabBar: {
border: false
},
items: [{
title: 'Active Tab 1',
html: 'Active Link One',
xtype: 'pie-custom',
}, {
title: 'Active Tab 2',
html: 'Active Link Two'
}, {
title: 'Active Tab 3',
html: 'Active Link Three'
}, {
title: 'Active Tab 4',
html: 'Active Link Four'
}]
});
app/view/main/Pie.js
Ext.define('App.view.main.Pie', {
extend: 'Ext.Panel',
xtype: 'pie-custom',
// <example>
bodyStyle: 'background: transparent !important',
layout: {
type: 'vbox',
pack: 'center'
},
// </example>
width: 650,
initComponent: function() {
var me = this;
//<example>
me.tbar = [
'->',
{
text: 'Preview',
handler: function() {
me.down('polar').preview();
}
}
];
//</example>
me.items = [{
xtype: 'polar',
width: '100%',
height: 500,
store: {type: 'device-market-share'},
insetPadding: 30,
innerPadding: 20,
legend: {
docked: 'bottom'
},
interactions: ['rotate', 'itemhighlight'],
sprites: [{
type: 'text',
text: 'Pie Charts - Custom Slice Sizing',
font: '22px Helvetica',
width: 100,
height: 30,
x: 40, // the sprite x position
y: 20 // the sprite y position
}, {
type: 'text',
text: 'Data: IDC Predictions - 2017',
font: '10px Helvetica',
x: 12,
y: 425
}, {
type: 'text',
text: 'Source: Internet',
font: '10px Helvetica',
x: 12,
y: 435
}],
series: [{
type: 'pie',
animation: {easing: 'easeOut', duration: 500},
angleField: 'data1', // bind angle span to visits
lengthField: 'data2', // bind pie slice length to views
clockwise: false,
highlight: {
margin: 20
},
label: {
field: 'os', // bind label text to name
display: 'outside',
font: '14px Arial'
},
style: {
strokeStyle: 'white',
lineWidth: 1
},
tooltip: {
trackMouse: true,
renderer: function(storeItem, item) {
this.setHtml(storeItem.get('os') + ': ' + storeItem.get('data1') + '%');
}
}
}]
//<example>
}, {
style: 'padding-top: 10px;',
xtype: 'gridpanel',
columns : {
defaults: {
sortable: false,
menuDisabled: true
},
items: [
{ text: 'OS', dataIndex: 'os' },
{ text: 'Market Share', dataIndex: 'data1', width: 150, renderer: function(v) { return v + '%'; } },
{ text: 'Growth', dataIndex: 'data2', width: 150, renderer: function(v) { return v + '%'; } }
]
},
store: {type: 'device-market-share'},
width: '100%'
//</example>
}];
this.callParent();
}
});
can you help me out why is this error happen ???
Try to add "ext-charts" to "requires" section of your app.json in line 42

Can we use Grid inside Sencha Container?

I want to display a list from sencha store. I want to display it as a table with header, hence I thought Grid would be perfect for it. But I am getting this errorUncaught TypeError: Cannot call method 'substring' of undefined Is it because I used Grid as an item in Container? If not whats the problem, how can I achieve my goal? I have commented out Grid. I used a "list" to display records but as I want to add a header to the list, I think Grid would do it more easily.'Ext.define("PocketCRM.view.InvestorsList", {
extend: "Ext.Container",
requires: [
"Ext.dataview.List",
],
alias: "widget.investorslistview",
config: {
layout: {
type: "vbox",
},
items: [
{
xtype: "toolbar",
docked: "top",
title: "Investor Details",
items: [
{
xtype: "button",
ui: "back",
text: "Back",
itemId: "backToDeal"
}
]
},
{
xtype: "label",
html: "Select a Client Area"
},
{
xtype: "list",
store: "Investors",
itemId : "InvestorsList",
onItemDisclosure: true,
indexBar: false,
grouped: false,
disableSelection: false,
loadingText: "Loading Investors...",
emptyText: '<div class="leads-list-empty-text">No Investors found.</div>',
itemCls : "dataview-item",
itemTpl:[
'<table border="0" cellpadding="2" cellspacing="2" style="width:95%; margin-top:0px;"><tr>',
'<td style="width:20%; text-align: center; line-height: 3; font-size: 16px;">{Account__c}</td>',
'<td style="width:20%; text-align: center; line-height: 3; font-size: 16px;">{Primary_Contact_Name__c}</td>',
'<td style="width:20%; text-align: center; line-height: 3; font-size: 16px;">{Status__c}</td>',
'<td style="width:15%; text-align: center; line-height: 3; font-size: 16px;">{Contact_Phone__c}</td>',
'<td style="width:20%; text-align: center; line-height: 3; font-size: 16px;">{Primary_Contact_Email__c}</td>',
'</tr></table>'
],
listeners : {
scope : this,
itemtap : function(dataview, index, el, record, e){
//Browser event e
console.log(e.target,Ext.get(e.target).getAttribute('id'));
var formPanel = Ext.create('Ext.form.Panel',{
modal : true,
hideOnMaskTap : true,
centered : true,
scrollable : 'vertical',
width : 400,
height : 200,
layout: { type: 'vbox', align: 'stretch' },
items:[{
xtype: 'selectfield',
name: 'Status__c',
label: 'Status',
options: [
{text: 'Pending', value: 'Pending'},
{text: 'Accepted', value: 'Accepted'},
{text: 'Final Bidder', value: 'Final Bidder'},
{text: 'Dropped', value: 'Dropped'},
{text: 'Rejected', value: 'Rejected'},
{text: 'Closed', value: 'Closed'}
]
},
{xtype: 'spacer'},
{xtype: 'spacer'},
{
xtype: 'button',
//width : 100,
text: 'Save',
handler: function(){
console.log('Inside Save');
var InvStore = Ext.getStore('Investors');
InvStore.sync();
console.log('Completed Sync');
formPanel.hide();
}
},
{xtype: 'spacer'},
{
xtype: 'button',
text: 'Cancel',
//width : 100,
handler: function(){
formPanel.hide();
}
}]
});
formPanel.setRecord(record);
Ext.Viewport.add(formPanel).show();
}
}
},
{
//xtype: "grid.panel",
//columns: [
// {text: 'Account', dataIndex:'Account__c'},
//],
},
],
listeners: [
{
delegate: "#backToDeal",
event: "tap",
fn: "onBackDealTap"
},
{
delegate: "#InvestorsList",
event: "disclose",
fn: "onInvestorsListDisclose"
}
]
},'
The xtype is not grid.panel, it's just grid.
Relevant doc link: http://docs.sencha.com/touch/2.3.1/#!/api/Ext.grid.Grid

get active tab on button click in extjs

I just want to get active tab on 'save' button click in extjs code.
my code is given below:
Ext.require([
'Ext.tab.*',
'Ext.window.*',
'Ext.tip.*',
'Ext.layout.container.Border'
]);
Ext.define('WebCare.UI.RoleManagerAdminWindow', {
extend: 'Ext.window.Window',
id: 'rolemanageradminwindow',
modal: true,
title: 'Manage Role & Permission',
closable: true,
closeAction: 'hide',
width: 600,
height: 550,
minWidth: 700,
minHeight: 200,
layout: 'border',
bodyStyle: 'padding: 5px;',
listeners: {
show: function (sender, eOpts) {
var self = sender;
vent.trigger("WindowLoad");
}
},
items: [
{
id: 'rolemanageradmintab',
region: 'center',
xtype: 'tabpanel',
constructor: function (config) {
var self = this;
self.callParent(config);
},
items: [
{
xtype: 'rolemanagereditor',
id:'1'
},
{
xtype: 'agencyeditor',
id: '2'
}
],
listeners: {
'tabchange': function (tabPanel, tab) {
}
}
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
ui: 'footer',
defaults: { minWidth: 70 },
style: {
background: "#d6e3f3"//, "#d9ebff",
},
height: 40,
items: [
{ xtype: 'component', flex: 1 },
Ext.create('Ext.button.Button', {
height: 25,
text: 'Close',
disabled: false,
handler: function () {
this.up('.window').close();
}
}),
Ext.create('Ext.button.Button', {
height: 25,
text: 'Save',
disabled: false,
handler: function () {
}
})
]
}
]
});
A simple example to get the active tab in the tabpanel when you click Save button.
Ext.onReady(function() {
var tabPanel = Ext.create('Ext.tab.Panel', {
width: 300,
height: 200,
activeTab: 0,
items: [
{
title: 'Tab 1',
bodyPadding: 10,
html: 'A simple tab'
},
{
title: 'Tab 2',
html: 'Another one'
},
{
title: 'Tab 3',
html: 'Another one'
}
],
buttons: [
{
text: 'Save',
handler: function() {
var activeTab = tabPanel.getActiveTab();
alert("The active tab in the panel is " + activeTab.title);
}
}
],
renderTo: Ext.getBody()
});
});

Resources