Related
I'm facing issue of firing edit event using cell editor in Ext Js 3.4.
I'm trying to achieve triggering an ajax call upon a cell edited after pressing 'Enter'.
For now, I just replaced with console.log('hi') but it doesn't show anything after I pressed 'Enter'.
I'm not sure what's wrong in my code. Appreciate if someone can point it out. Thanks.
var grid = new Ext.grid.EditorGridPanel({
store: api_store,
loadMask: true,
clicksToEdit: 1,
tbar: [{
text: 'Create',
handler: function () { }
}],
columns: [
{
id: 'name',
header: 'Key Name',
width: 300,
sortable: true,
dataIndex: 'name',
editor: {
xtype: 'textfield',
allowBlank: false,
listener: {
edit: function (el) {
console.log('hi');
}
}
}
},
{
header: 'Key Value',
width: 500,
sortable: false,
dataIndex: 'key'
}
],
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
viewConfig: {
forceFit: true
},
height: 210,
stripeRows: true,
height: 350,
title: 'Keys'
});
Solution:
Use EditorGridPanel afteredit event:
afteredit(e)
Fires after a cell is edited. The edit event object has the following
properties
grid - This grid
record - The record being edited
field - The field name being edited
value - The value being set
originalValue - The original value for the field, before the edit.
row - The grid row index
column - The grid column index
Parameters:
e : Object An edit event (see above for description)
Example:
Ext.onReady(function () {
var api_store = new Ext.data.ArrayStore({
fields: ['key', 'name'],
data: [
['1', 'Name1'],
['2', 'Name2'],
['3', 'Name3']
]
});
var grid = new Ext.grid.EditorGridPanel({
renderTo: Ext.getBody(),
store: api_store,
loadMask: true,
clicksToEdit: 1,
tbar: [{
text: 'Create',
handler: function () { }
}],
listeners: {
afteredit: function(e) {
console.log('After edit. Column: ' + e.field);
}
},
columns: [
{
id: 'name',
header: 'Key Name',
width: 300,
sortable: true,
dataIndex: 'name',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'Key Value',
width: 500,
sortable: false,
dataIndex: 'key'
}
],
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
viewConfig: {
forceFit: true
},
height: 210,
stripeRows: true,
height: 350,
title: 'Keys'
});
});
Looking for some assistance on showing/hiding a form container element based on a combobox selection.
I only want the grid (id: NspList) to show if and only if "NSP Provider" is selected in the combobox (id: carrierConnectivity). Does anyone have any ideas how this can be accomplished? Code snippet below:
{
xtype: 'container',
layout: 'vbox',
style: { paddingRight: '10px', paddingBottom: '10px' },
items: [{
xtype: 'combobox',
labelAlign: 'top',
fieldLabel: 'Connectivity Type',
id: 'carrierConnectivity',
name: 'connectivity_type',
store:['GRE', 'GRE - with internet peering', 'MPLS', 'Direct Leased Line', 'NSP Partner'],
width: 250,
},
{
id: 'NspList',
flex: 1,
xtype: 'grid',
minHeight: 200,
maxHeight: 300,
width: 250,
selType: 'rowmodel',
title: 'NSP Providers',
forceFit: true,
bind: { store: '{nspnames}' },
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
],
columns: {
defaults: {
editor: 'textfield'
},
items: [
{ text: 'Name', dataIndex: 'name'}
]
},
tools: [
{type: 'plus', handler: 'addNsp'},
{type: 'minus', handler: 'removeNsp'}
]
}
]
}
The combobox has a change listener which you want to use:
listeners:{
change:function(cb,newValue) {
cb.nextSibling().setVisible(newValue=="NSP Partner");
}
}
Because you haven't selected NSP Partner as default value on the checkbox, you should configure the grid as hidden by default:
hidden:true
I have a button inside ExtJs toolbar as below
Ext.define('Member.view.members.MembersGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.membersGrid',
id: 'membersGrid',
cls: 'custom-grid',
requires: [],
viewConfig : {
enableTextSelection: true
},
frame: true,
store: '',
//id: 'transGrid',
height: 150,
columns: [
{
xtype: 'rownumberer'
},
{
hidden:true,
width: 10,
dataIndex: 'id',
text: 'id'
},
/*{
width: 100,
//flex: 1,
dataIndex: 'member_number',
text: 'Member Number'
},*/
{
width: 150,
flex: 1,
dataIndex: 'member_names',
text: 'Member Names'
}],
dockedItems: [
{
xtype: 'toolbar',
itemId: 'toptoolbar',
id:'toptoolbar',
flex: 1,
dock: 'top',
items: [
{
xtype: 'button',
text: 'Pin_Reset',
id: 'pinReset',
itemId: 'pinReset',
iconCls: 'pin_reset'
}
]
}
],
initComponent: function() {
Ext.getCmp('pinReset').hidden = true;
this.callParent();
}
});
I want the button to appear hidden after render. I thought Ext.getCmp('pinReset').hidden = true; will do since I have assigned the button an id. Getting the following error 'Cannot set property 'hidden' of undefined' on Chrome developer tools.
Extjs Version: 5.1
initComponent is called before the rendering.So it is not able to find the button.You can use 'afterrender' event instead for this.
Add following code instead of initComponent:
listeners:{
afterrender: function() {
Ext.getCmp('pinReset').hidden = true;
}
}
Working Code:
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.grid.Panel', {
alias: 'widget.membersGrid',
id: 'membersGrid',
cls: 'custom-grid',
renderTo:Ext.getBody(),
requires: [],
viewConfig : {
enableTextSelection: true
},
frame: true,
store: '',
//id: 'transGrid',
height: 150,
columns: [
{
xtype: 'rownumberer'
},
{
hidden:true,
width: 10,
dataIndex: 'id',
text: 'id'
},
/*{
width: 100,
//flex: 1,
dataIndex: 'member_number',
text: 'Member Number'
},*/
{
width: 150,
flex: 1,
dataIndex: 'member_names',
text: 'Member Names'
}],
dockedItems: [
{
xtype: 'toolbar',
itemId: 'toptoolbar',
id:'toptoolbar',
flex: 1,
dock: 'top',
items: [
{
xtype: 'button',
text: 'Pin_Reset',
id: 'pinReset',
itemId: 'pinReset',
iconCls: 'pin_reset'
}
]
}
],
listeners:{
afterrender: function() {
Ext.getCmp('pinReset').hidden = true;
}
}
});
}
});
<link rel="stylesheet" href="https://extjs.cachefly.net/ext-4.1.1-gpl/resources/css/ext-all.css">
<script type="text/javascript" src="https://extjs.cachefly.net/ext-4.1.1-gpl/ext-all-debug.js"></script>
You are using initComponent instead of afterRender in your codesnippet. Is that correct?
I would use the reference-property and use it like this:
items: [
{
xtype: 'button'
reference: 'myButton'
}
]
...
afterRender: function() {
this.lookupReference('myButton').setHidden(true);
this.callParent();
}
1) Create a grid and add a coulmn of type 'timefield' in grid with renderer of format ('h:i A').
2) Add a row and mke a selection in 'timefield' column, say 4:00 AM.
3) Add another adjecent row and select the same data i.e. 4:00 AM in the dropdown. You will not be able to do this action, and you need to select another time and then come back to the initial selection. It looks to be an ExtJS bug. how to solve this issue.
I have code the following in grid
this.mcmGridPanel = new Ext.grid.GridPanel({ height: 360, width: 680, title: 'Shifts', store: App.mcmAgentShiftStore, multiSelect: true, x: 0, y: 100, columns: [
{ xtype: 'gridcolumn', header: 'Name', width: 120, dataIndex: 'Name',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{ xtype: 'gridcolumn', header: 'Initials', width: 45, dataIndex: 'Initials',
editor: { xtype: 'textfield' }
},
{ xtype: 'gridcolumn', header: 'Employee Id', width: 75, dataIndex: 'EmployeeId',
editor: {
xtype: 'numberfield',
allowBlank: false
}
},
{ xtype: 'gridcolumn', header: 'Phone#', width: 100, dataIndex: 'MobilePhoneId',
editor: {
//TCS: 12/3/2013 cell phone table modified
xtype: 'combobox',
typeAhead: true,
editable: true,
triggerAction: 'all',
selectionOnTab: true,
// lazyRender: true,
// forceSelection: true,
store: App.mcmAllMobilePhoneStore,
displayField: 'MobileIdentifier',
valueField: 'MobilePhoneId',
value: 'MobilePhoneId',
queryMode: 'local',
queryDelay: 100,
specialkey: function(f, e) {
if(e.getKey() === e.ESC) {
this.hide(); }
},
listeners: {
load: function(store, recs, success) {
if(Ext.typeOf(this.getPicker().loadMask) != "boolean") {
console.log("trying to hide the loadmask");
this.getPicker().loadMask.hide();
}
}
}
},
> renderer: function(value,metaData,record) {
if(value) {
var MobileStore = Ext.getStore( App.mcmAllMobilePhoneStore);
var Record = MobileStore.findRecord('MobilePhoneId', value);
return Record ? Record.get('MobileIdentifier'): record.get('MobileIdentifier');
} else return "";
}//TCS: 12/3/2013 cell phone table modified end*/ },
{ xtype: 'datecolumn', header: 'Start Date', width: 84, dataIndex: 'StartAvailability', format: 'Y-m-d',
editor: {
xtype: 'datefield',
allowBlank: false,
format: 'Y-m-d'
}
},
{ header: 'Start', width: 65, dataIndex: 'StartAvailabilityTime', format: 'H:i',
editor: {
xtype: 'timefield',
id: starttime,
format: 'H:i',
increment: 15,
allowBlank: false
}
},
{ xtype: 'datecolumn', header: 'End Date', width: 84, dataIndex: 'EndAvailability', format: 'Y-m-d',
editor: {
xtype: 'datefield',
allowBlank: false,
format: 'Y-m-d'
}
},
{ header: 'End', width: 65, dataIndex: 'EndAvailabilityTime', format: 'H:i',
editor: {
xtype: 'timefield',
id: endtime,
format: 'H:i',
increment: 15,
allowBlank: false
}
} ], tbar: [
{
text: 'Add',
tooltip: 'Add Shift',
iconCls: 'icon-shift-add',
scope: me,
handler: function() {
var agent = this.mcmAgentCombobox.getValue();
if(agent) {
addShift.call(this, agent);
} else {
App.mcmShowMessageBox({
title: 'Important',
message: 'Please select an agent',
time: 2000
});
}
}
},
{
itemId: 'removeShift',
text: 'Remove',
tooltip: 'Remove Selected Shifts',
iconCls: 'icon-shift-remove',
scope: me,
handler: function() {
this.mcmRemoveShifts();
},
disabled: true
},
{
itemId: 'closeoutShift',
text: 'Closeout',
tooltip: 'Closeout Selected Shifts',
iconCls: 'icon-shift-closeout',
scope: me,
handler: function() {
var selection = this.mcmGridPanel.getSelectionModel().getSelection();
if(selection.length && selection.length > 1) {
App.mcmShowMessageBox({
title: 'Important',
message: 'Please enter a single shift to perform closeout',
time: 2000
});
return;
}
App.mcmCloseoutShift(selection[0]);
},
disabled: true
},
//TCS: 12/3/2013 cell phone table modification
{
text: 'Add Cell Phone',
tooltip: 'Add CellPhone',
iconCls: 'icon-cellphone-add',
scope: this,
handler: function()
{
this.hide;
App.mcmShowMobilePhoneWindow();
}
},
//TCS: 12/3/2013 cell phone table modification end ], plugins: [ this.mcmRowEditing ], viewConfig: {}, listeners: {
scope: me,
beforeedit : function(editor, e) {
editor.down('[#id=starttime]').clearValue();
editor.down('[#id=endtime]').clearValue();
} }
I reset the values before edit. but it not working.
I need to add one or more records at a time in grid. After click on the add button i can able to add one record at a time. but he thing is i need to add multiple record at a time.
I tried to use both clickToEdit, clicksToMoveEditor but not working.
I need to align the check box in center while edit the grid.
Main thing is while i able edit in grid i can able to only the fields except startdate and end date column. it not rendered from the database.
Can anyone help me if there is wrong config params for the grid.
this.mcmRowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1,
autoCancel: true,
listeners: {
scope: this,
canceledit: function(editor, event) {
if(!editor.record.get('FocusMarketId')) { //if it was a brand new record
console.log("edit");
console.log(editor.record.get('Id'));
var sm = this.mcmGridPanel.getSelectionModel();
App.mcmFocusMarketStore.remove(sm.getSelection());
if(sm.getCount()) {
sm.select(0);
}
}
}
}
});
var addFocusMarket = function(focusmarket) {
this.mcmRowEditing.cancelEdit();
console.log("add focus market");
var record = new Sch.model.Resource({
Id: focusmarket ? focusmarket.Id : '',
Origin: focusmarket ? focusmarket.Origin : '',
Destination: focusmarket ? focusmarket.Destination: '',
CabinClass: focusmarket ? focusmarket.CabinClass: '',
StartAvailability: focusmarket ? focusmarket.startAvailability: '',
EndAvailability: focusmarket ? focusmarket.endAvailability: ''
});
console.log("records-->"+record);
App.mcmFocusMarketStore.insert(0, record);
this.mcmRowEditing.startEdit(0, 0);
this.mcmHasChanges = true;
};
this.mcmGridPanel = new Ext.grid.GridPanel({
height: 240,
width: 540,
title: 'Results',
store: App.mcmFocusMarketStore,
multiSelect: true,
x: 0,
y: 170,
columns: [
{ xtype: 'gridcolumn', text: 'Flight#', sortable: true, width: 100, dataIndex: 'FlightNumber', hidden: true,
editor: {
xtype: 'textfield',
maxLength: 4,
minLength: 4,
maxChars: 4,
}
},
{ xtype: 'gridcolumn', text: 'Origin', sortable: true, width: 100, dataIndex: 'Origin',
editor: {
xtype: 'textfield',
maxLength: 3,
minLength: 3,
maxChars: 3,
}
},
{ xtype: 'gridcolumn', text: 'Destination', sortable: true, width: 100, dataIndex: 'Destination',
editor: {
xtype: 'textfield',
maxLength: 3,
minLength: 3,
maxChars: 3,
}
},
{ xtype: 'gridcolumn', text: 'Cabin', sortable: true, width: 80, dataIndex: 'CabinClass',
editor: {
xtype: 'textfield',
maxLength: 1,
minLength: 1,
maxChars: 1,
}
},
{ xtype: 'datecolumn', text: 'Start Date', width: 100, dataIndex: 'StartAvailability', format: 'd/m/Y',
editor: {
xtype: 'datefield',
format: 'd/m/Y'
}
},
{ xtype: 'datecolumn', text: 'End Date', width: 100, dataIndex: 'EndAvailability', format: 'd/m/Y',
editor: {
xtype: 'datefield',
format: 'd/m/Y'
}
},
{
xtype: 'gridcolumn',
text: 'Delete?',
header: 'Delete?',
dataIndex: 'delete',
width: 60,
renderer: function (value, meta, record, rowIndex, colIndex) {
return '<center><input type="checkbox" id="Delete-' + rowIndex + '"/></center>';
},
listeners :
{
checkchange : function(column, recordIndex, checked)
{
this.mcmRemoveFocusMarket();
//or send a request
}
},
handler: function() {
/* var sm = grid.getSelectionModel();
rowEditing.cancelEdit();
store.remove(sm.getSelection());
if (store.getCount() > 0) {
sm.select(0);
}*/
},
//disabled: true,
editor: {
xtype: 'checkbox'
}
}
],
tbar: [
{
text: 'Add',
tooltip: 'Add Focus Market',
iconCls: 'icon-shift-add',
scope: me,
handler: function() {
addFocusMarket.call(me);
}
}
],
plugins: [ this.mcmRowEditing ],
1.)
Do not add records into the grid directly.
Add data to the backend and reload the store of the grid then to show newly added data in the grid
2)
Alignment should be fixed with the use of checkcolumn
3)
I am not really sure what you are asking here.
Editing seems to work from what I understand.
Are you sure you are providing data for datecolumns in the right format (date: '2014/02/04')?
// Presuming you are using ExtJS 4...
this.mcmRowEditing = Ext.create('Ext.grid.plugin.RowEditing',
{
clicksToEdit: 1,
autoCancel: true,
listeners: {
scope: this,
edit: function(editor, context, eOpts){
// do your editing processing here
// lookup api documentation for params
}
}
});
this.mcmGridPanel = Ext.create('Ext.grid.Panel',
{
height: 240,
width: 540,
title: 'Results',
store: App.mcmFocusMarketStore,
multiSelect: true,
x: 0,
y: 170,
columns: [
{ xtype: 'gridcolumn', text: 'Flight#', sortable: true, width: 100, dataIndex: 'FlightNumber', hidden: true,
editor: {
xtype: 'textfield',
maxLength: 4,
minLength: 4,
maxChars: 4,
}
},
{ xtype: 'gridcolumn', text: 'Origin', sortable: true, width: 100, dataIndex: 'Origin',
editor: {
xtype: 'textfield',
maxLength: 3,
minLength: 3,
maxChars: 3,
}
},
{ xtype: 'gridcolumn', text: 'Destination', sortable: true, width: 100, dataIndex: 'Destination',
editor: {
xtype: 'textfield',
maxLength: 3,
minLength: 3,
maxChars: 3,
}
},
{ xtype: 'gridcolumn', text: 'Cabin', sortable: true, width: 80, dataIndex: 'CabinClass',
editor: {
xtype: 'textfield',
maxLength: 1,
minLength: 1,
maxChars: 1,
}
},
{ xtype: 'datecolumn', text: 'Start Date', width: 100, dataIndex: 'StartAvailability', format: 'd/m/Y',
editor: {
xtype: 'datefield',
format: 'd/m/Y'
}
},
{ xtype: 'datecolumn', text: 'End Date', width: 100, dataIndex: 'EndAvailability', format: 'd/m/Y',
editor: {
xtype: 'datefield',
format: 'd/m/Y'
}
},
{ xtype: 'checkcolumn', text: 'Delete?', width: 60, dataIndex: 'delete', format: 'd/m/Y',
// Make checkboxes of checkcolumn unchangeable. Editor can change state then.
// Handle changes in CellEditing/RowEditing 'edit' event for consistent behavior with other columns.
listeners: {beforecheckchange: function(column, recordIndex, checked){return false}}
editor: {xtype: 'checkbox'},
// checkcolumn aligns center by default use the 2 lines below instead if you want to align left
//align: 'left',
//editor: {xtype: 'checkbox', style: 'text-align:left; display:inline; padding-left:10px;'},
}
],
tbar: [
{
text: 'Add',
tooltip: 'Add Focus Market',
iconCls: 'icon-shift-add',
scope: me,
handler: function() {
addFocusMarket.call(me);
}
}
],
plugins: [ this.mcmRowEditing ]
});