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

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

Related

Extjs Tree and GRID content

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

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

Adding rows to grid

I am trying to add rows to my grid.
I saw an example in the docs:
onAddRouteClick: function(){
// Create a model instance
var rec = new KitchenSink.model.grid.Plant({
buying_vendor_id: 12,
country_code: '1',
route: 0
});
this.getStore().insert(0, rec);
this.cellEditing.startEditByPosition({
row: 0,
column: 0
});
}
But i cant seem to make it work in my code.
This is my grid:
onBtnRoutesSearchClick: function(button, e, options){
var me = this;
var v_url = 'GetRoutes.jsp?' + Ext.urlEncode({'route_id': routeID, 'route_country_code' : routeCountryCode , 'route_vendor_id' : routeVendorID});
var newTab = Ext.create('Ext.panel.Panel', {
id: 'routes_pannel',
title: 'Routes',
autoScroll: true,
layout: {
type: 'fit'
},
closable: true,
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
id: 'buttonResetBid',
icon: 'images/Plus.png',
text: 'Add Row',
listeners: {
click: {
fn: me.onAddRouteClick,
scope: me
}
}
}
]
}
],
items: [{
id: 'routes_grid',
xtype: 'gridpanel',
autoShow: false,
autoScroll: true,
store: Ext.create('Ext.data.Store', {
fields:[
{name: 'buying_vendor_id', type: 'int', sortType: 'asInt'},
{name: 'country_code', type: 'int', sortType: 'asInt'},
{name: 'route', type: 'int', sortType: 'asInt'}
],
proxy: {
type: 'ajax',
timeout: 120000,
url: v_url,
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
},
autoLoad: true
}),
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'buying_vendor_id',
width: 100,
text: 'Buying Vendor'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
width: 100,
text: 'Country Code'
},
{
xtype: 'gridcolumn',
dataIndex: 'route',
width: 80,
text: 'Route'
}
],
}]
});
var panel = Ext.getCmp("MainTabPanelID");
panel.add(newTab).show();
}
Any ideas?
1.Create your model
Ext.define('Product', {
extend: 'Ext.data.Model',
fields: [
{name: 'ProductID'},
{name: 'ProductName'},
{name: 'UnitPrice'},
{name: 'UnitsInStock'}
]
});
2.create your rowEditing
var rEditor = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
listeners: {edit: function (editor, e) { }); }
});
3.get Store and create your grid
var grid = Ext.create('Ext.grid.Panel', {
store: store,
plugins: [rEditor],
title: 'Products',
columns: [ ],
dockedItems: [ {
xtype: 'toolbar',
dock: 'top',
items: [ {
xtype: 'button',
text: 'Yeni',
listeners: {
click: {
fn: function () { store.insert(0, new Product()); rEditor.startEdit(0, 0); }
}
}
} ]
} ],
width: 450,
renderTo: Ext.getElementById('hede')
});

Adding an empty row to a grid

I am trying to add rows to my grid.
I saw an example in the docs:
onAddRouteClick: function(){
// Create a model instance
var rec = new KitchenSink.model.grid.Plant({
buying_vendor_id: 12,
country_code: '1',
route: 0
});
this.getStore().insert(0, rec);
this.cellEditing.startEditByPosition({
row: 0,
column: 0
});
}
this.getStore().insert(0, rec);
this.cellEditing.startEditByPosition({
row: 0,
column: 0
});
}
But i cant seem to make it work in my code.
This is my grid:
onBtnRoutesSearchClick: function(button, e, options){
var me = this;
var v_url = 'GetRoutes.jsp?' + Ext.urlEncode({'route_id': routeID, 'route_country_code' : routeCountryCode , 'route_vendor_id' : routeVendorID});
var newTab = Ext.create('Ext.panel.Panel', {
id: 'routes_pannel',
title: 'Routes',
autoScroll: true,
layout: {
type: 'fit'
},
closable: true,
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
id: 'buttonResetBid',
icon: 'images/Plus.png',
text: 'Add Row',
listeners: {
click: {
fn: me.onAddRouteClick,
scope: me
}
}
}
]
}
],
items: [{
id: 'routes_grid',
xtype: 'gridpanel',
autoShow: false,
autoScroll: true,
store: Ext.create('Ext.data.Store', {
fields:[
{name: 'buying_vendor_id', type: 'int', sortType: 'asInt'},
{name: 'country_code', type: 'int', sortType: 'asInt'},
{name: 'route', type: 'int', sortType: 'asInt'}
],
proxy: {
type: 'ajax',
timeout: 120000,
url: v_url,
reader: {
type: 'json',
root: 'data',
successProperty: 'success'
}
},
autoLoad: true
}),
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'buying_vendor_id',
width: 100,
text: 'Buying Vendor'
},
{
xtype: 'gridcolumn',
dataIndex: 'country_code',
width: 100,
text: 'Country Code'
},
{
xtype: 'gridcolumn',
dataIndex: 'route',
width: 80,
text: 'Route'
}
],
}]
});
var panel = Ext.getCmp("MainTabPanelID");
panel.add(newTab).show();
1.Create your model
Ext.define('Product', {
extend: 'Ext.data.Model',
fields:
[
{ name: 'ProductID' },
{ name: 'ProductName' },
{ name: 'UnitPrice' },
{ name: 'UnitsInStock' }
]
});
2.create your rowEditing
var rEditor = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
listeners:
{
edit: function (editor, e) { });
}
});
3.get Store and create your grid
var grid = Ext.create('Ext.grid.Panel', {
store: store,
plugins: [rEditor],
title: 'Products',
columns:
[
],
dockedItems:
[
{
xtype: 'toolbar',
dock: 'top',
items:
[
{
xtype: 'button',
text: 'Yeni',
listeners:
{
click:
{
fn: function () {
store.insert(0, new Product());
rEditor.startEdit(0, 0);
}
}
}
}
]
}
],
width: 450,
renderTo: Ext.getElementById('hede')
});
So you are trying to add a record to store right?
OK, lets look at the Store API
http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add
Sample usage:
myStore.add({some: 'data'}, {some: 'other data'});
The best practice is to also create a Model class . Read the component guides on grid and the data package .

Resources