Grid combobox and textfield editor - change emptyText dynamically and clear field - extjs

In the following example with cellediting I want to dynamically change the emptyfield textfield editor and clear the field.
However, if I select the first item in the combobox I get the textfield reference, but only once. If after I selecting another item in the combobox I can no longer get the textfield reference or change the emptyText.
Also I can not clear the textfield value when selecting one combobox item.
FIDDLE: https://fiddle.sencha.com/#view/editor&fiddle/2g3d
Ext.create('Ext.data.Store', {
storeId: 'mystore',
fields:[ 'type', 'description'],
});
var combostore = Ext.create('Ext.data.Store', {
fields:[ 'name'],
data:[
{'name' : 'Phone'},
{'name' : 'Mobile'},
{'name' : 'Email'}
]
});
Ext.create('Ext.data.Model', {
fields:[
{name:'type', type:'string'},
{name:'description', type:'string'}
]
});
Ext.create('Ext.form.Panel', {
title: 'Order Info',
width: 400,
bodyPadding: 10,
defaults: {
anchor: '100%',
padding: 5
},
items: [{
xtype: 'gridpanel',
selModel: 'rowmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
pluginId: 'celleditingId'
},
header:{
titlePosition: 0,
items:[{
xtype:'button',
text: 'Add row',
handler: function(btn){
var record = Ext.create('Ext.data.Model', {});
var grid = btn.up('grid'),
rowediting = grid.getPlugin('celleditingId');
grid.store.insert(0,{});
rowediting.startEdit(0, 0);
}
}]
},
title: 'Contact',
store: Ext.data.StoreManager.lookup('mystore'),
columns: [{
text: 'Type',
dataIndex: 'type',
editor:{
xtype: 'combobox',
name: 'type',
valueField: 'name',
displayField: 'name',
store: combostore,
queryMode: 'local',
markDirty:false,
listeners: {
select: function (combo, record, eOpts){
var columnTextfieldEditor = Ext.ComponentQuery.query('#textfieldEd')[0].editor,
grid = combo.up('grid');
if (combo.value === 'Phone') {
Ext.apply(columnTextfieldEditor, {
emptyText: 'First text',
submitEmptyText: false
});
var row = grid.getSelectionModel().getSelection()[0];
grid.getPlugin('celleditingId').startEditByPosition({
row: grid.store.indexOf(row),
column: 1
});
// columnTextfieldEditor.setValue('');
}else {
var row = grid.getSelectionModel().getSelection()[0];
grid.getPlugin('celleditingId').startEditByPosition({
row: grid.store.indexOf(row),
column: 1
});
Ext.apply(columnTextfieldEditor, {
emptyText: 'Second text',
submitEmptyText: false
});
}
console.log(combo.value);
console.log(columnTextfieldEditor);
}
}
},
flex: 0.7
},{
text: 'Description',
dataIndex: 'description',
itemId: 'textfieldEd',
editor:{
xtype: 'textfield',
name: 'description'
},
flex: 1
}],
listeners:{
afterrender: function(grid){
var record = Ext.create('Ext.data.Model', {});
rowediting = grid.getPlugin('celleditingId');
grid.store.insert(0,{});
rowediting.startEdit(0, 0);
}
},
height: 200
}],
renderTo: Ext.getBody(),
});

Just change this:
var columnTextfieldEditor = Ext.ComponentQuery.query('#textfieldEd')[0].editor
To This:
var columnTextfieldEditor = Ext.ComponentQuery.query('#textfieldEd')[0].getEditor()
And Change the order of the second "apply":
Ext.apply(columnTextfieldEditor, {
emptyText: 'Second text',
submitEmptyText: false
});
grid.getPlugin('celleditingId').startEditByPosition({
row: grid.store.indexOf(row),
column: 1
});

Related

Height specified is not the real one on extjs

Hi guys i need help with grid panel, I set the height of the grid to 200px and when I see the grid on the browser it has 600px. I tried to force height with setHeight(), but didn't work.
The code for the grid panel is the next:
for(var i=0; i<json.length;++i){
var data = JSON.parse(json[i].json);
var store = Ext.create('Ext.data.Store', {
fields: ['question', 'type', 'answer'],
data: data.questions
});
var rEditor = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 2,
listeners:{
edit: function (editor, e) { }
}
});
var itemId ="";
if(json[i].enabled){
act++;
itemId = 'active'+act;
}else{
inact++
itemId = 'inactive'+inact;
}
var grid = Ext.create('Ext.grid.Panel', {
height: 200,
margin: '20 35 0 35',
title: 'Group of Questions',
store: store,
plugins: [rEditor],
itemId: itemId,
stateId: itemId,
columns: [
{xtype: 'rownumberer', stateId: itemId+'_1', width:30},
{ text: 'Question', dataIndex: 'question', stateId: itemId+'_2', tdCls: 'gridTree', flex: 1, editor: {xtype: 'textfield'}},
{ text: 'Type', dataIndex: 'type', stateId: itemId+'_3', tdCls: 'gridTree', flex: 1, editor: {xtype: 'combobox', fieldLabel: 'Choose Type', store: types,queryMode: 'local', valueField: 'name',tpl: Ext.create('Ext.XTemplate','<tpl for=".">','<div class="x-boundlist-item">{name}</div>','</tpl>'), displayTpl: Ext.create('Ext.XTemplate','<tpl for=".">','{name}','</tpl>')}},
{ text: 'Answer', dataIndex: 'answer', stateId: itemId+'_4', tdCls: 'gridTree', flex: 1, editor: {xtype: 'textfield', store: types, }}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
scale: 'medium',
glyph: Rd.config.icnLight,
listeners: {
click: {
fn: function(){
Ext.Ajax.request({
url: '',
method: 'POST',
params: {
country: country,
language: language,
realm_id: realm_id,
},
});
}
}
}
},
]
}
],
});
if(json[i].enabled){
active.add(grid);
actives.push(grid);
}else{
inactive.add(grid);
inactives.push(grid);
}
}
I forget to say that in the same container i can have more than one grid panel. I don't know if this is possible. Can you guys tell me please.

How to display a panel based on combobox selection in ExtJS

Here is my code:
{
xtype: 'combo',
width: 150,
value: 'select last..',
store: new Ext.data.SimpleStore({
data: [
[0, 'first'],
[1, 'second'],
[2, 'third']
],
id: 0,
fields: ['value', 'text']
}),
valueField: 'value',
displayField: 'text',
triggerAction: 'all',
editable: false,
name: 'lastComboSelection',
itemId: 'lastCombo',
listeners: {
change: function (combo, newValue, oldValue) {
//based on selection want to display a panel
}
}
},{
xtype: 'firstPanel',
name: 'first text field'
},{
xtype: 'SecondPanel',
name: 'second text field '
},{
xtype: 'thirdPanel',
name: 'last text field '
}
Here is the Change method to select a panel via combo
And here is the simple fiddle example fiddle
Regards:
Salman Hassan :)
listeners: {
change: function(combo, newVal, oldVal, eOpts) {
if (newVal == 'Select Panel 1') {
var panel1 = Ext.ComponentQuery.query("#panel1")[0].show();
var panel2 = Ext.ComponentQuery.query("#panel2")[0].hide();
var panel3 = Ext.ComponentQuery.query("#panel3")[0].hide();
} else if (newVal == 'Select Panel 2') {
var panel1 = Ext.ComponentQuery.query("#panel1")[0].hide();
var panel2 = Ext.ComponentQuery.query("#panel2")[0].show();
var panel3 = Ext.ComponentQuery.query("#panel3")[0].hide();
} else if (newVal == 'Select Panel 3') {
var panel1 = Ext.ComponentQuery.query("#panel1")[0].hide();
var panel2 = Ext.ComponentQuery.query("#panel2")[0].hide();
var panel3 = Ext.ComponentQuery.query("#panel3")[0].show();
}
}
}
If you are using Ext JS version 5.0 or above, then bind the selection property of combobox to activeItem property of a container with panels as its child items. The layout for this container would be card. For example:
Ext.define('OnlyOnePanel', {
extend: 'Ext.panel.Panel',
viewModel: {},
layout: 'vbox',
items: [{
xtype: 'combobox',
width: 150,
emptyText: 'Select..',
store: new Ext.data.SimpleStore({
data: [
[0, 'first'],
[1, 'second'],
[2, 'third']
],
fields: ['value', 'text']
}),
valueField: 'value',
displayField: 'text',
value: 'first',
triggerAction: 'all',
editable: false,
name: 'lastComboSelection',
itemId: 'lastCombo',
bind: {
selection: '{selectedItem}'
}
}, {
xtype: 'container',
layout: 'card',
bind: {
activeItem: '{selectedItem.value}'
},
items: [{
xtype: 'panel',
html: 'First Panel'
}, {
xtype: 'panel',
html: 'Second Panel'
}, {
xtype: 'panel',
html: 'Third Panel'
}]
}]
});
Check this fiddle.

how to send value from grid (pop up) to form panel in extjs

how to show data in form panel after click one of data in pop up in grid view, I have try another way but always wrong,
this is my grid panel :
var tt = Ext.define('Rendering.view.beli.dataSupplier', {
extend: 'Ext.form.Panel',
//extend: 'Ext.window.Window',
// xtype: 'beligrid',
alias : 'widget.contatoform',
frame: true,
// id: 'detailPanelis',
title: 'Company data',
bodyPadding: 5,
layout: 'column',
requires: [
'Ext.grid.*',
'Ext.form.*',
'Ext.layout.container.Column'
],
initComponent: function() {
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: 'onSelectionChanges'
}
}];
//];
// });
this.callParent(arguments);
},
onSelectionChanges: function(model, records) {
//alert('yuhuuuu');
var editt = Ext.create('Rendering.view.beli.bg_beli');
var c = editt.onSelectionChange(model, records);
}
});
the function for to send data to form panel is
listeners: {
scope: this,
selectionchange: 'onSelectionChanges'
}
this is function of onSelectionChanges :
onSelectionChanges: function(model, records) {
//alert('yuhuuuu');
var editt = Ext.create('Rendering.view.beli.bg_beli');
var c = editt.onSelectionChange(model, records);
}
and form panel :
var tt = Ext.define('Rendering.view.beli.bg_beli', {
extend: 'Ext.form.Panel',
xtype: 'beligrid',
controller: 'binding-dynamic',
frame: true,
title: 'Company data',
bodyPadding: 5,
layout: 'column',
requires: [
'Ext.grid.*',
'Ext.form.*',
'Ext.layout.container.Column'
],
// In this example, configuration is applied at initComponent time
// because it depends on profileInfo object that is generated for the
// FormGrid instance.
initComponent: function() {
//Ext.apply(this, {
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: 'onSelectionChange'
}
},{
columnWidth: 0.35,
margin: '20 0 0 10',
xtype: 'form',
title:'Company detailsss',
layout: 'anchor',
defaultType: 'textfield',
items: [
{
name : 'id_supplier',
fieldLabel: 'id',
hidden:true
},{
fieldLabel: 'Nama Supplier',
name: 'namaSupplier'
},{
fieldLabel: 'email',
name: 'email'
},{
fieldLabel: 'alamat',
name: 'address'
},{
xtype: 'button',
text: 'YUY',
action: 'add'
}]
}];
//];
// });
this.callParent(arguments);
},
onSelectionChange: function(model, records) {
alert('asdasd');
console.log(records);
var rec = records[0];
console.log(rec);
if (rec) {
var c = this.getForm().loadRecord(rec);
// this.getBeliStoreStore().load();
console.log(this.getForm().loadRecord(rec));
}
}
});
I send data from grid to form panel, and the function that accepted data in form panel is :
onSelectionChange: function(model, records) {
alert('asdasd');
console.log(records);
var rec = records[0];
console.log(rec);
if (rec) {
var c = this.getForm().loadRecord(rec);
// this.getBeliStoreStore().load();
console.log(this.getForm().loadRecord(rec));
}
}
please help, I have looking for to any reference but I don't get answer yet, thanks before
My suggestion is modify the call for event this.onSelectionChange or like that this.on('selectionchange',this.onSelectionChange) it is another way for call events in extjs
initComponent: function() {
var me = this ;
this.items = [
{
columnWidth: 0.65,
xtype: 'gridpanel',
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}],
listeners: {
scope: this,
selectionchange: me.onSelectionChanges
}
}];
//];
// });
this.callParent(arguments);
}
OR
initComponent: function() {
var me = this ;
var grid = Ext.create('Ext.grid.Panel', {
reference: 'customerGrid',
store: 'BeliStore',
columns : [{
text: 'Nama',
dataIndex: 'namaSupplier',
flex: 1
}, {
text: 'Alamat',
dataIndex: 'address',
flex: 1
}
]});
me.items = [
{
columnWidth: 0.65,
grid
}];
grid.on('selectionchange',me.onSelectionChange)
this.callParent(arguments);
}
http://docs.sencha.com/extjs/4.2.5/#!/example/build/KitchenSink/ext-theme-neptune/#form-grid

EXT JS - on click transfer record to store of popup grid panel

This is my popup with tabs.
I need to give a value from record to gridpanel in tab 2 in store to get attributes from server side by category_id. Searched answer in official documentation and didn't find.
Can help me somebody?
Ext.define('desk.view.CategoryPopup', {
extend: 'Ext.window.Window',
alias: 'widget.categorypopup',
title: 'Change Category',
layout: 'fit',
autoShow: true,
bdoyPadding: 10,
initComponent: function(){
this.items = [{
xtype: 'tabpanel',
items: [
{
xtype: 'form',
title: 'Add / Edit / Delete Category',
items: [
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Parent Category'
},
{
xtype: 'textfield',
name: 'new',
fieldLabel: 'New Category'
},
{
xtype: 'textfield',
name: 'id',
fieldLabel: 'Category ID',
hidden: true
},
{
xtype: 'textfield',
name: 'parent',
fieldLabel: 'Parent ID',
hidden: true
}
],
bodyPadding: 10
},
{
xtype: 'gridpanel',
alias: 'widget.categoryattr',
title: 'Attributes',
height: 350,
buttons: [{'text': 'Add attribute', 'action' : 'add-attribute'}],
columns: [
{
name: 'Name',
dataIndex: 'name'
}
],
width: 300,
store: Ext.widget('categoryattributes')
}
]
}];
this.buttons = [
{
text: 'Update',
action: 'add'
},
{
text: 'Delete',
action: 'delete'
}
];
this.callParent(arguments);
}
})
This is function in controller
editCategories: function(grid, record){
var view = Ext.widget('categorypopup');
view.down('form').loadRecord(record);
}
you need something like this:
editCategories: function(grid, record){
var view = Ext.widget('categorypopup');
view.down('form').loadRecord(record);
Ext.Ajax.request({
url: '/api/category/'+ record.getId() +'/attributes', //example url insert your webservice
success: function(response){
var attributes = Ext.decode(response.responseText);
view.down('grid').getStore().loadData(attributes);
}
});
}
you will need a store with a model for your grid.

Sencha ExtJs Grid refresh after saving store

I have an ExtJS grid with a toolbar button to save the date. The save works and the data is stored. But the grid is not refreshed. How do I reload the grid data after the save?
Ext.define('MyLodge.view.content.MemberGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.membergrid',
initComponent: function(){
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var store = Ext.create('MyLodge.store.Members');
Ext.apply(this, {
height: this.height,
plugins: [rowEditing],
store: store,
stripeRows: true,
columnLines: true,
columns: [{
id :'id',
text: 'ID',
width: 40,
sortable: true,
dataIndex: 'id'
},{
text : 'Name',
flex: 1,
sortable : true,
dataIndex: 'name',
field: {
xtype: 'textfield'
}
},{
text : 'E-Mail',
width : 150,
sortable : true,
dataIndex: 'email',
field: {
xtype: 'textfield'
}
},{
text : 'Href',
width : 200,
sortable : true,
dataIndex: 'href',
field: {
xtype: 'textfield'
}
}],
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Add',
iconCls: 'icon-add',
handler: function(){
// empty record
store.insert(0, new MyLodge.model.Member());
rowEditing.startEdit(0, 0);
}
}, {
text: 'Delete',
iconCls: 'icon-delete',
handler: function(){
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
},'-',{
text: 'Save',
iconCls: 'icon-save',
handler: function(){
store.sync();
}
}]
}]
});
this.callParent(arguments);
}
});
You can load store in callback of sync
store.sync({
success: function( response ) {
store.load();
}
});
You will probably want to call store.reload() in a callback from store.save() (what is store.save() anyway? it is not part of Ext.data.Store interface)

Resources