Extjs Tree and GRID content - extjs

I have a simple Extjs (5.1.1) Tree menu:
var menu = new Ext.tree.Panel( {
root: {
text: 'My menu',
expanded: true,
listeners: {
itemclick: function(s,r) {
alert(r.data.text);
}
},
children: [{
text: 'System',
expanded: true,
children: [{
text: '',
leaf: true
}, {
text: 'System Users',
leaf: true
}, {
text: 'System Administrators',
leaf: true
}]
}, {
text: 'Settings',
expanded: true,
children: [{
text: 'Passwords',
leaf: true
}, {
text: 'Emails',
leaf: true
}, ]
}, {
text: 'Logs',
leaf: true,
}]
}
});
Ext.application({
name : 'MVC',
launch : function() {
Ext.create('Ext.container.Viewport', {
extend: 'Ext.container.Viewport',
layout: 'border',
items: [
{
title: 'North',
region: 'north',
height: 50,
xtype: 'container'
},
{
title: 'Menu',
region:'west',
floatable: false,
items: menu,
width: 300
},
{
title: 'Center',
region: 'center'
}
]
});
}
});
My problem: The contents (GRID) have some js file. And I would like click one of the tree menu than js load 'Center' item. But I don't know how. :-(
Example system_users.js file: (This file should load on center when I click System Users on the Tree.)
var Users = {
init: function () {
itemdblclick: this.editDocument
},
edit: function(grid, roWindex, e) {
var id = grid.getStore().getAt(rowIndex);
Users.openEditForm(id);
},
openEditForm: function(id){
// form open
}
};
Users.init();
Ext.application({
name : 'Users',
launch : function() {
Ext.widget({
renderTo : Ext.getBody(),
xtype : 'grid',
title : 'Users',
height : 800,
store : {
fields : [ 'login_id',
'login_name',
'login_firstname',
'login_middlename',
'login_lastname',
'login_email',
'login_mobile',
'login_status' ],
autoLoad : true,
proxy: {
type: 'ajax',
api: {
read: 'http://users/select',
create: 'http://users/insert',
update: 'http://users/update',
destroy: 'http://users/delete'
},
reader: {
type: 'json',
successProperty: 'success',
root: 'data',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: false,
root: 'data'
}
}
},
columns: {
items: [
{ text: 'ID', dataIndex: 'login_id', editor: 'textfield', width: 200 },
{ text: 'Login Name', dataIndex: 'login_name', editor: 'textfield', width: 200 },
{ text: 'Firstname', dataIndex: 'login_firstname', editor: 'textfield', width: 200 },
{ text: 'Middlename', dataIndex: 'login_middlename', editor: 'textfield', width: 200 },
{ text: 'Lastname', dataIndex: 'login_lastname', editor: 'textfield', width: 200 },
{ text: 'Email', dataIndex: 'login_email', editor: 'textfield', width: 200 },
{ text: 'Mobile', dataIndex: 'login_mobile', editor: 'textfield', width: 200 },
{ text: 'Status', dataIndex: 'login_status', editor: 'textfield', width: 200 }
]
},
listeners: {
itemdblclick: function(dv, record, item, index, e) {
// This is row index
alert(index);
}
}
})
}
});

Related

How to configurate Ext.grid.plugin.Editable buttons?

I requires Ext.grid.plugin.Editable in my grid. Now I want to change classes inside default panel, witch slides right for editing of row.
But I don't understand how I to manage submit and delete button function (for example I want to define POST for submit button).
toolbarConfig - doesn't work
Ext.define('Foresto.model.EditListRenters', {
extend: 'Ext.grid.Grid',
xtype: 'rentlist',
requires: [ //some plugins and models
],
frame: true,
store: {
model: 'Foresto.model.RentsListModel',
autoLoad: true,
pageSize: 0,
proxy: {
type: 'ajax',
url: '/api/renter/',
reader: {
type: 'json',
rootProperty: 'results'
}
}
},
plugins: [{
type: //someplugins}
],
/* toolbarConfig: {
xtype:'titlebar',
docked:'top',
items:[{
xtype:'button', // it is don't work
ui:'decline',
text:'decline',
align: 'right',
action:'cancel'
}]
}, */
columns: [{
text: 'id',
dataIndex: 'id'
}, {
text: 'document',
dataIndex: 'document',
editable: true,
flex: 1
}, {
text: 'document_num',
dataIndex: 'document_num',
editable: true
}, {
text: 'legal_type',
dataIndex: 'legal_type',
editable: true
}, {
text: 'fio_represent',
dataIndex: 'fio_represent',
editable: true
}, {
text: 'position_represent',
dataIndex: 'position_represent',
editable: true,
}, {
text: 'certificate',
dataIndex: 'certificate',
editable: true,
}]
});
Here is an example of a grid with a custom form:
https://fiddle.sencha.com/#view/editor&fiddle/2ojt
// model
Ext.define('Fiddle.model.Document', {
extend: 'Ext.data.Model',
fields: [{
name: 'id',
type: 'int'
}, {
name: 'document',
type: 'string'
}, {
name: 'type',
type: 'string'
}]
});
//view (grid)
Ext.define('Fiddle.view.DocumentGrid', {
extend: 'Ext.grid.Panel',
xtype: 'documentlist',
store: {
model: 'Fiddle.model.Document',
data: [{
id: 1,
document: 'My First Doc',
type: 'pdf'
}, {
id: 2,
document: 'My Second Doc',
type: 'pdf'
}]
},
columns: [{
text: 'id',
dataIndex: 'id'
}, {
text: 'Document',
dataIndex: 'document',
flex: 1
}, {
text: 'Type',
dataIndex: 'type',
}]
});
var form = Ext.create('Ext.form.Panel', {
title: 'Form',
region: 'east',
layout: {
type: 'vbox',
algin: 'stretch'
},
collapsible: true,
bodyPadding: 10,
hidden: true,
items: [{
xtype: 'textfield',
name: 'document',
fieldLabel: 'Document'
}, {
xtype: 'combo',
name: 'type',
fieldLabel: 'type',
store: ['pdf', 'doc', 'docx', 'odf']
}],
buttons: [{
text: 'Save',
handler: function () {
form.updateRecord();
form.hide();
}
}]
});
var grid = Ext.create('Fiddle.view.DocumentGrid', {
title: 'Document Grid',
region: 'center',
listeners: {
selectionchange: function (selModel, selection) {
if (Ext.isEmpty(selection)) {
form.hide();
return;
}
form.loadRecord(selection[0]);
form.show();
}
}
});
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.panel.Panel', {
renderTo: Ext.getBody(),
layout: 'fit',
layout: 'border',
width: 600,
height: 600,
items: [
grid, form
]
});
}
});

Extjs Modern Grid column cell tool conditional iconCls

In a grid column config, I have a cell tool for which I'd like the iconCls of the tool to be conditional on the row record data.
},{
text: 'Favorite',
//dataIndex: 'favorite',
width: 80,
align: 'center',
cell: {
tools: {
play : {
iconCls:'x-fa yellow fa-star',
align:'center',
tooltip : 'Toggle Favorites',
handler: 'onFavoriteToggle'
}
}
}
}, {
I'd like the icon cls to be based on the row record favorite property (true/false), to be fa-star or fa-star-o
Does anyone know how to accomplish this?
I answered this elsewhere so I'll post it here as well for anyone else interested. You can use binding to do it:
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.Viewport.add({
xtype: 'grid',
itemConfig: {
viewModel: true
},
store: {
data: [{
name: 'A',
fav: false
}, {
name: 'B',
fav: true
}]
},
columns: [{
dataIndex: 'name'
}, {
text: 'Favorite',
width: 80,
align: 'center',
cell: {
tools: {
play : {
bind: {
iconCls:'x-fa yellow {record.fav ? "fa-star" : "fa-star-o"}',
},
align:'center',
tooltip : 'Toggle Favorites',
handler: function(grid, context) {
var r = context.record;
r.set('fav', !r.get('fav'));
}
}
}
}
}]
});
}
});
Fiddle
You can use renderer method of gridcolumn.
In renderer function you need to use gridcell.setTools() method.
In this FIDDLE, I have created a demo as per you requirement. Hope this will guide you or help you to achieve you requirement.
var companyStore = Ext.create('Ext.data.Store', {
fields: ['name', 'price', {
name: 'lastChange',
type: 'date'
}, {
name: 'favorite',
type: 'boolean'
}],
autoLoad: true,
pageSize: null,
proxy: {
type: 'ajax',
url: 'company.json',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Ext.create('Ext.grid.Grid', {
title: 'Company Data',
store: companyStore,
columns: [{
text: 'Company',
flex: 1,
dataIndex: 'name'
}, {
text: 'Price',
flex: 1,
dataIndex: 'price',
formatter: 'usMoney'
}, {
text: 'Last Updated',
flex: 1,
dataIndex: 'lastChange',
formatter: 'date("d M Y")'
}, {
width: 100,
text:'Favorite',
align: 'center',
renderer: function (value, rec, col, cell) {
cell.setTools({
play: {
iconCls: rec.get('favorite') ? 'x-fa yellow fa-star' : 'x-fa yellow fa-star-o',
tooltip: 'Toggle Favorites'
}
});
}
}],
height: 500,
layout: 'fit',
renderTo: Ext.getBody(),
fullscreen: true
});

ExtJS5 Web Desktop Sample: Unable to fire event from controller

I have been working with web desktop example in ExtJS5. The example has static data and no events. I wanted to implement a click event on 'Remove Something' button on grid window. Here is my modified code:
Ext.define('SampleApp.view.main.GridWindow', {
extend: 'Ext.ux.desktop.Module',
requires: [
'Ext.data.ArrayStore',
'Ext.util.Format',
'Ext.grid.Panel',
'Ext.grid.RowNumberer'
],
init: function () {
this.launcher = {
text: 'Grid Window',
iconCls: 'icon-grid'
};
},
controller: 'gridwindow',
createWindow: function () {
var desktop = this.app.getDesktop();
var win = desktop.getWindow('grid-win');
if (!win) {
win = desktop.createWindow({
id: 'grid-win',
title: 'Grid Window',
width: 740,
height: 480,
iconCls: 'icon-grid',
animCollapse: false,
constrainHeader: true,
layout: 'fit',
items: [
{
border: false,
xtype: 'grid',
store: mock.view.main.GridWindow.getDummyData(),
columns: [{ xtype: 'rownumberer', sortable: false, text: "S.N.", width: 70 }, {
id: 'topic',
text: "Topic",
dataIndex: 'gridTopic',
flex: 1,
align: 'center'
}, {
text: "Author",
dataIndex: 'gridAuthor',
flex: 1,
align: 'center',
sortable: true
}, {
text: "Replies",
dataIndex: 'gridReplies',
align: 'center',
flex: 1,
sortable: true
}, {
id: 'last',
text: "Last Post",
dataIndex: 'gridLastPost',
flex: 1,
align: 'center',
sortable: true
}]
}
],
tbar: [{
text: 'Add Something',
tooltip: 'Add a new row',
iconCls: 'add'
}, '-', {
text: 'Options',
tooltip: 'Modify options',
iconCls: 'option'
}, '-', {
text: 'Remove Something',
tooltip: 'Remove the selected item',
iconCls: 'remove',
listeners: {
click: 'onDeleteClick'
}
}]
});
}
return win;
},
statics: {
getDummyData: function () {
var _store = Ext.create('Ext.data.Store', {
fields: [
{ name: 'gridId', type: 'int' },
{ name: 'gridTopic', type: 'string' },
{ name: 'gridAuthor', type: 'string' },
{ name: 'gridReplies', type: 'string' },
{
name: 'gridLastPost', type: 'date', convert: function (value) {
var _date = new Date(value);
return Ext.Date.format(_date, "Y-m-d H:i:s");
}
}
]
});
var _responseText;
Ext.Ajax.request({
async: false,
url: 'http://localhost/sampleapp/getusers',
method: 'GET',
success: function (resp) {
_responseText = Ext.decode(resp.responseText);
_store.loadData(_responseText);
}
});
return _store;
}
}
});
I am unable to handle 'onDeleteClick' event inside the controller. Here is the controller definition:
Ext.define('SampleApp.view.main.GridWindowController', {
extend: 'Ext.app.ViewController',
alias: 'controller.gridwindow',
onDeleteClick: function (button, evt) {
alert('Clicked');
}
});
Can someone point out the mistake. How can this event be handled?
Ext.ux.desktop.Module does not accept controller config option.
Use your controller on an Ext.Component — in your case either the grid or the window.

EXT JS how come the cellmodel are not editable?

Ext.define('RouteFareModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'Rate_ID', type: 'number'},
{name: 'Route_Fare' , type: 'int'},
'From_LocationName',
'To_LocationName',
'From_LocationID',
'To_LocationID',
'from_name',
'to_name',
'Route_ID',
'Normal_Rate',
'Discounted_Rate']
});
var RouteFareStore = Ext.create('Ext.data.JsonStore', {
model: 'RouteFareModel',
storeId: 'RouteFareStore',
autoLoad: false,
sorters: [{
property: 'Route_Fare',
direction: 'ASC'
}],
proxy: {
type: 'ajax',
url: 'get-routefare.php',
api: {
create: 'insert-routeseq.php',
//read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
update: 'update-routeseq.php',
//destroy: 'http://visual04/ModuleGestion/php/Pays.php?action=destroy'
},
actionMethods: 'POST',
baseParams: {
_id : 0,
},
reader: {
type: 'json',
idProperty: '_id'
},
writer: {
type: 'json',
id: '_id'
}
}
});
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
Ext.define('MyApp.view.MyGridPanelRouteFare', {
extend: 'Ext.grid.Panel',
id:'MyGridPanelRouteFare',
alias: 'widget.mygridpanelroutefare',
renderTo: Ext.getBody(),
height: window.innerHeight,
width: window.innerWidth/3,
title: 'Route Fare Setting',
selModel: {
selType: 'cellmodel'
},
plugins: [cellEditing],
store: RouteFareStore,
columns: [
{
xtype:'gridcolumn',
width: 120,
dataIndex: 'from_name',
text: 'From Location'
},
{
xtype:'gridcolumn',
width: 120,
dataIndex: 'to_name',
text: 'To Location'
},
{
xtype:'gridcolumn',
width: 80,
dataIndex: 'Normal_Rate',
text: 'Normal Rate'
},
{
xtype:'gridcolumn',
width: 80,
dataIndex: 'Discounted_Rate',
text: 'Discount Rate'
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
height: 30,
items: [
{
xtype: 'combobox',
id:'cmbFareRouteID',
width: 191,
store: RouteNameStore,
valueField : "_id",
displayField : "Route_Code",
fieldLabel: 'Route Code',
labelWidth: 70,
editable: false,
queryMode: 'local',
listeners: {
select: function( combo, records, eOpts ) {
console.log("Combo selected _id : "+records[0].get('_id'));
RouteFareStore.load({
params:{
_id: records[0].get('_id')
}
});
}
}
},
{
xtype: 'button',
cls: '',
id: 'BtnFareCmbRefresh',
width: 65,
icon: '',
iconCls: 'refresh',
text: 'Refresh'
}
]
},
{
xtype: 'toolbar',
dock: 'top',
height: 30,
items: [
{
xtype: 'button',
cls: '',
id: 'BtnRouteFareSave',
width: 65,
icon: '',
iconCls: 'save',
text: 'Save'
},
{
xtype: 'button',
cls: '',
id: 'BtnRouteFareRefresh',
width: 65,
icon: '',
iconCls: 'refresh',
text: 'Refresh'
}
]
}
]
})
i have add
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
but the grid cell still not able to editable. why?
{
xtype:'gridcolumn',
width: 80,
dataIndex: 'Normal_Rate',
text: 'Normal Rate',
field: {
xtype: 'numberfield',
allowBlank: false,
minValue: 0,
maxValue: 1000
}
},
must insert field: {} , then the cellmodel able to editable already.

Passing arguments to Listener

I have a button:
var me = this;
...
var argumentToPass;
...
{
xtype: 'button',
text: 'text',
listeners: {
click: {
fn: me.onBtnAddToBidClick,
scope: me
}
}
}
...
me has a refferance to the argumentToPass.
And the Listerner:
onBtnAddToBidClick: function(button, e, options){
alert(argumentToPass)
}
Basicly i am trying to make a simple function(String var) method.
How can i get the scope from inside the Listener(onBtnAddToBidClick)
EDIT: Thsi is most of my code:
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.selection.CheckboxModel'
]);
var sm = Ext.create('Ext.selection.CheckboxModel');
Ext.define('MyApp.view.MyViewport', {
extend: 'Ext.container.Viewport',
layout: {
type: 'border'
},
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'panel',
region: 'west',
id: 'MenuPanelID',
width: 255,
layout: {
type: 'accordion'
},
collapsed: true,
collapsible: true,
title: 'תפריט',
items: [
{
xtype: 'form',
width: 148,
layout: {
align: 'stretch',
type: 'vbox'
},
collapsed: false,
title: 'מחירונים',
dockedItems: [
{
xtype: 'textfield',
flex: 1,
dock: 'top',
id: 'txtPrefixID',
margin: 10,
fieldLabel: 'Prefix',
labelWidth: 50
},
{
xtype: 'button',
flex: 1,
dock: 'top',
margin: 10,
text: 'חפש',
listeners: {
click: {
fn: me.onBtnPrefixSearchClick,
scope: me,
arg: 0
}
}
},
{
xtype: 'button',
flex: 1,
dock: 'top',
margin: 10,
text: 'חפש טווח',
listeners: {
click: {
fn: me.onBtnPrefixSearchClick,
scope: me,
arg: 1
}
}
}
]
}
]
},
{
xtype: 'tabpanel',
region: 'center',
id: 'MainTabPanelID',
activeTab: 0,
items: [
{
xtype: 'panel',
layout: {
type: 'border'
},
title: 'General',
items: [
{
xtype: 'container',
region: 'center',
layout: {
align: 'stretch',
type: 'vbox'
},
items: [
{
xtype: 'gridpanel',
flex: 1,
autoScroll: true,
title: 'שיחות נכנסות',
store: 'IncomingDataStore',
viewConfig: {
id: 'IncomingGridId'
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'trunk_owner',
text: 'Owner'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_name',
text: 'Country'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
text: 'Code'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'operator_prefix',
text: 'Operator Prefix',
format: '00'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'call_duration',
text: 'Duration Hourly'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'acd',
text: 'ACD Hourly'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'asr',
text: 'ASR Hourly'
},
{
xtype: 'numbercolumn',
align: 'right',
dataIndex: 'calls',
text: 'Calls Hourly',
format: '0,000'
}
],
listeners: {
celldblclick: {
fn: me.onIncomingGridpanelCellDblClick,
scope: me
}
}
}
]
}
]
}
]
}
]
});
me.callParent(arguments);
},
onBtnPrefixSearchClick: function(arg) {
var checkBoxPrefixes = Ext.create('Ext.selection.CheckboxModel');
var val = Ext.getCmp('txtPrefixID').value;
var v_url = 'GetCountryPrefixes.jsp?' + Ext.urlEncode({'prefix': val, 'action': 'search_exact'});
alert(arg);
if arg === 0 {
// do something...
}
var me = this;
var newTab = Ext.create('Ext.panel.Panel', {
id: 'prefix_panel',
title: 'Price Usage Report',
autoScroll: true,
layout: {
type: 'fit'
},
closable: true,
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
id: 'buttonBiding',
icon: 'images/dollar16x16.png',
text: 'הוסף להצעת מחיר',
listeners: {
click: {
fn: me.onBtnAddToBidClick,
scope: me
}
}
}
]
}
],
items: [{
id: 'prefix_grid',
xtype: 'gridpanel',
autoShow: false,
autoScroll: true,
selModel: checkBoxPrefixes,
store: Ext.create('Ext.data.Store', {
fields: [
{name: 'price_date'}, //, type: 'Date' , sortType: 'asDate', format: 'Y-m-d h:M:s'
{name: 'country_code',type: 'int', sortType: 'asInt'},
{name: 'prefix',type: 'int', sortType: 'asInt'},
{name: 'vendor_name'},
{name: 'rate', type: 'float', sortType: 'asFloat'},
{name: 'currency'},
{name: 'quality', type: 'int', sortType: 'asInt'},
{name: 'duration',type: 'int', sortType: 'asInt'},
{name: 'acd', type: 'float', sortType: 'asFloat'}
],
proxy: {
type: 'ajax',
timeout: 120000,
url: v_url,
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
},
autoLoad: true
}),
title: 'Price Reprort for "' + val + '" - Monthly' ,
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'price_date',
width: 80,
text: 'Date',
renderer: Ext.util.Format.dateRenderer('Y-m-d')
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
text: 'Counry Code',
width: 80
},
{
xtype: 'gridcolumn',
dataIndex: 'prefix',
text: 'Prefix',
width: 80
},
{
xtype: 'gridcolumn',
dataIndex: 'vendor_name',
width: 100,
text: 'Vendor Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'currency',
width: 100,
text: 'Currency'
},
{
xtype: 'gridcolumn',
dataIndex: 'rate',
width: 50,
text: 'Rate'
},
{
xtype: 'gridcolumn',
dataIndex: 'quality',
width: 50,
text: 'Quality'
},
{
xtype: 'gridcolumn',
dataIndex: 'duration',
width: 100,
text: 'Duration'
},
{
xtype: 'gridcolumn',
dataIndex: 'acd',
width: 100,
text: 'ACD'
}
]
}]
});
var panel = Ext.getCmp("MainTabPanelID");
panel.remove('prefix_panel');
panel.add(newTab).show();
},
You cannot do it because you are not able to modify event args of a defined event.
But you can store the arguments you want to pass into the instance that fires the event or into the scope in which the event callback get executed. In that way you will have access to them either by the first event arg, which is in nearly all situations the instance that fires the event or by the this keyword when you have applied them to the scope.
Simplified example with data stored in callback scope:
fiddle

Resources