How to display a panel based on combobox selection in ExtJS - 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.

Related

extjs form,combo and hiddenname

Have this code.
Ext.define('App.v2.model.Things', {
extend: 'App.v2.model.Base'
,fields: [{
name: 'C'
,type:'int'
},{
name:'NAME'
,type:'string'
},{
name:'SHORT_NAME'
,type:'string'
}]
,proxy:{
url:'/data/data1.php'
,reader : {
rootProperty: 'data'
},
extraParams: {
limit: 1000
}
},
idProperty: 'C'
});
model for document
Ext.define('App.v2.model.ThingsList', {
extend: 'App.v2.model.Base'
,fields: [{
name: 'C'
,type:'int'
},
{
name: 'THING_ID',
type:'int'
},
{
name: 'ZE',
type:'int'
},
{
name: 'HS',
type:'int'
},
{
name: 'THING_NAME',
type:'string'
},]
,proxy:{
url:'/data/thingsList.php'
,reader : {
rootProperty: 'data'
}
},
idProperty: 'C'
});
Form config
items: [{
xtype: 'form',
bodyStyle: 'border:none',
defaultType: 'textfield',
layout: 'fit',
maindata: [{
xtype: 'panel',
//layout: 'vbox',
layout: 'vbox',
id: 'ThingsForm',
items: [{
xtype: 'textfield',
fieldLabel: 'ЗЕ',
name: 'ZE',
width: 400,
allowBlank: false
},
{
xtype: 'textfield',
fieldLabel: 'HS',
name: 'HS',
width: 400,
allowBlank: false
},
{
xtype: 'combo',
fieldLabel: 'Thing',
name: 'THING_ID',
hiddenName: 'THING_NAME',
valueField: 'C',
displayField: 'SHORT_NAME',
store : {
model:'App.v2.model.Things',
autoLoad: true,
}
}
//]
]
}]
}]
load data to form
row = grid.store.getAt(this.conf.grid.getSelectionModel().getCurrentPosition().rowIdx);
form = this.down('form').getForm();
form.loadRecord(row);
all good. Form show values
after change of form try to update record
var record = form.getRecord(); // see old values of THING_ID and THING_NAME
record.set(form.getValues()); // see new value of THING_ID and OLD value of THING_NAME
How update THING_NAME to NEW value (TEXT) selected on COMBO in record?
only like describe there?
ExtJS 5 combobox - submitting both value and text

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

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

Ext JS 6.5 - modern grid disabled not working

I am working on Ext JS 6.5 modern. I have some condition to disable the grid component, user has only rights to view the grid no one else.
I have tried disabled config and disable method but not working. Here is my Fiddle.
Code snippet
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.data.Store', {
storeId: 'gridStore',
fields: ['name'],
data: [{
name: 'Test 1'
}, {
name: 'Test 2'
}, {
name: 'Test 3'
}, {
name: 'Test 4'
}]
});
Ext.create({
xtype: 'grid',
layout: 'fit',
fullscreen: true,
title: 'Baisc grid example',
store: 'gridStore',
//Here I have put {disabled: true} but not working
disabled: true,
columns: [{
text: 'Name',
flex: 1,
dataIndex: 'name'
}],
listeners: {
childtap: function (grid, location, eOpts) {
alert('childtap');
}
},
items: [{
xtype: 'toolbar',
items: {
xtype: 'button',
ui: 'action',
text: 'Disabled grid',
iconCls: 'x-fa fa-ban',
handler: function () {
//IT is also not working
this.up('grid').setDisabled(true);
this.up('grid').disable();
}
}
}]
//renderTo:Ext.getBody()
});
}
});
Somebody please help me with a solution for disabling the grid component.
As a workaround we can use grid.setMasked(true);
Here is the example Fiddle.
Another approach is to set grid's hideMode to opacity and then set it to hidden (this.up('grid').setHidden(true);).
For Example (editing your fiddle)
Ext.create('Ext.data.Store', {
storeId: 'gridStore',
fields: ['name'],
data: [{
name: 'Test 1'
}, {
name: 'Test 2'
}, {
name: 'Test 3'
}, {
name: 'Test 4'
}]
});
Ext.create({
xtype: 'grid',
layout: 'fit',
fullscreen: true,
title: 'Baisc grid example',
store: 'gridStore',
//Here I have put {disabled: true} but not working
//disabled: true,
hideMode: 'opacity',
columns: [{
text: 'Name',
flex: 1,
dataIndex: 'name'
}],
listeners: {
childtap: function (grid, location, eOpts) {
alert('childtap');
}
},
items: [{
xtype: 'toolbar',
items: {
xtype: 'button',
ui: 'action',
text: 'Disabled grid',
iconCls: 'x-fa fa-ban',
handler: function () {
this.up('grid').setHidden(true);
}
}
}]
//renderTo:Ext.getBody()
});
Also you need this css override:
<style>
.x-hidden-opacity {
opacity: 0.2 !important; //default is 0
pointer-events: none;
}
</style>

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.

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.

Resources