The data for the grid looks something like this:
data: [{
field1: abc
field2: [
{value: 0, label: Blue},
{value: 1, label: Green}
]
},
{
field1: def
field2: [
{value: 0, label: Red},
{value: 1, label: Pink}
]
}]
grid component config looks something like:
{
xtype: 'grid',
....
columns: [
{
dataIndex: field1
},
{
dataIndex: field2
editor: {
xtype: combobox,
displayField: label,
valueField: value,
store: new someSampleStore();
}
}
]
}
Now, the grid's column #2 has a combobox.
For Grid's row 0, column 1; combobox dropdown should display these options: Blue, Green
For Grid's row 1, column 1; combobox dropdown should display these options: Red, Pink
Do I need to manually load the data into each combobox (each row) or is there any way I can specify config in column definition so that the combobox picks up data for 'field2' ?
Have a look at the code below. In essence it does what you want but only works after the first click. I'll let you figure that out. ;-)
Demo: https://fiddle.sencha.com/#fiddle/gec
Ext.application({
name: 'Fiddle',
launch: function() {
var comboStore = Ext.create('Ext.data.Store', {
fields: ['value', 'label'],
data: [{
name: '',
value: ''
}],
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Ext.create('Ext.data.Store', {
storeId: 'employeeStore',
fields: ['firstname', 'lastname', 'seniority', 'dep', 'hired'],
data: [{
firstname: "Michael",
lastname: "Scott",
seniority: 7,
dep: "Management",
hired: "01/10/2004",
comboData: [{
label: 'Test1',
value: 'testval1'
}, {
label: 'Test2',
value: 'testval2'
}, {
label: 'Test3',
value: 'testval3'
}]
}, {
firstname: "Dwight",
lastname: "Schrute",
seniority: 2,
dep: "Sales",
hired: "04/01/2004",
comboData: [{
label: 'Dwight1',
value: 'testval1'
}, {
label: 'Dwight2',
value: 'testval2'
}, {
label: 'Dwight3',
value: 'testval3'
}]
}, {
firstname: "Jim",
lastname: "Halpert",
seniority: 3,
dep: "Sales",
hired: "02/22/2006",
comboData: [{
label: 'Jim1',
value: 'testval1'
}, {
label: 'Jim2',
value: 'testval2'
}, {
label: 'Jim3',
value: 'testval3'
}]
}, {
firstname: "Kevin",
lastname: "Malone",
seniority: 4,
dep: "Accounting",
hired: "06/10/2007",
comboData: [{
label: 'Kevin1',
value: 'testval1'
}, {
label: 'Kevin2',
value: 'testval2'
}, {
label: 'Kevin3',
value: 'testval3'
}]
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Column Demo',
store: Ext.data.StoreManager.lookup('employeeStore'),
columns: [{
text: 'First Name',
dataIndex: 'firstname',
editor: {
xtype: 'combobox',
displayField: 'label',
valueField: 'value',
store: comboStore,
fields: ['value', 'label']
}
}, {
text: 'Last Name',
dataIndex: 'lastname'
}, {
text: 'Hired Month',
dataIndex: 'hired',
xtype: 'datecolumn',
format: 'M'
}, {
text: 'Department (Yrs)',
xtype: 'templatecolumn',
tpl: '{dep} ({seniority})'
}],
selType: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
listeners: {
beforeedit: function(editor, context, eOpts) {
testData = context.record.data.comboData;
comboStore.setData(testData);
}
}
},
width: 400,
forceFit: true,
renderTo: Ext.getBody()
});
}
});
Related
I have grid panel. I want to add a tree panel to a column in that grid panel.
Grid Panel
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields:[ 'name', 'email', 'phone'],
data: [
{ name: 'Lisa', email: 'lisa#simpsons.com', phone: '555-111-1224' },
{ name: 'Bart', email: 'bart#simpsons.com', phone: '555-222-1234' },
{ name: 'Homer', email: 'homer#simpsons.com', phone: '555-222-1244' },
{ name: 'Marge', email: 'marge#simpsons.com', phone: '555-222-1254' }
]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Tree Store
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: 'detention', leaf: true },
{ text: 'homework', expanded: true, children: [
{ text: 'book report', leaf: true },
{ text: 'algebra', leaf: true}
] },
{ text: 'buy lottery tickets', leaf: true }
]
}
});
For example,
If I want to this tree store to come under Name: Lisa i.e, tree expands when we click on Lisa. How can we do it.
Thank you.
What you are searching for is treegrid.
For modern toolkit, check modern treegrid.
For classic toolkit, check classic treepanel with multiple columns.
I have an editor comboBox in Grid and it only shows when I click row. How to keep it permanent visible in grid? Thanks
How to keep it permanent visible in grid?
If you are using ExtJS version 5.x or higher then you can use widgetcolumn
A widget column is configured with a widget config object which specifies an xtype to indicate which type of Widget or Component belongs in the cells of this column.
I have created an sencha fiddle demo hope this will help you to solve problem or achieve your requirement.
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone', {
name: 'checked',
defaultValue: 'AL'
}],
data: [{
name: 'Lisa',
email: 'lisa#simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart#simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer#simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge#simpsons.com',
phone: '555-222-1254'
}]
}),
states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "AL",
"name": "Alabama"
}, {
"abbr": "AK",
"name": "Alaska"
}, {
"abbr": "AZ",
"name": "Arizona"
}]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}, {
text: 'State',
width: 150,
xtype: 'widgetcolumn',
dataIndex: 'checked',
widget: {
xtype: 'combobox',
flex: 1,
emptyText: 'Select State',
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
store: states,
listeners: {
select: function (combo, record) {
Ext.Msg.alert('Success', 'Good you have selected <b>' + record.get('name') + '</b>')
var grid = combo.up('grid'),
index = grid.getView().indexOf(combo.el.up('table')),
record = grid.getStore().getAt(index);
console.log(record.getData());
}
}
}
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
I have a gridpanel with three columns I made these 3 columns as comboboxes using editor and I added a cell editing plugin. I should be able to add a row and select the values from the comboboxes coming from three different stores. The problem is I am unable to add a row which doesn't have a default grid store. How can I add a row in order to see the combobox columns to select values.
Here is the fiddle
"Grids are composed of two main pieces - a Ext.data.Store full of data and a set of columns to render."
You must add a store to gridpanel and then try to add a row to the store by clicking the add button. I have modified the code and is working now.
Ext.application({
models: [
'OneModel',
'TwoModel',
'ThreeModel'
],
views: [
'MyGridPanel'
],
name: 'combo',
launch: function() {
Ext.create('combo.view.MyGridPanel', {renderTo: Ext.getBody()});
}
});
Ext.define('combo.view.MyGridPanel', {
extend: 'Ext.grid.Panel',
alias: 'widget.mygridpanel',
requires: [
'combo.view.MyGridPanelViewModel',
'combo.view.MyGridPanelViewController',
'Ext.grid.column.Column',
'Ext.form.field.ComboBox',
'Ext.view.Table',
'Ext.toolbar.Toolbar',
'Ext.button.Button',
'Ext.grid.plugin.CellEditing'
],
store:Ext.create('Ext.data.Store',{
fields:[{
name:'One',
name:'Two',
name:'Three'
}]
}),
controller: 'mygridpanel',
viewModel: {
type: 'mygridpanel'
},
height: 501,
width: 562,
title: 'My Grid Panel',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'string',
text: 'One',
editor: {
xtype: 'combobox',
displayField: 'description',
valueField: 'description',
bind: {
store: '{oneStore}'
}
}
},
{
xtype: 'gridcolumn',
dataIndex: 'number',
text: 'Two',
editor: {
xtype: 'combobox',
displayField: 'lastname',
valueField: 'id',
bind: {
store: '{twoStore}'
}
}
},
{
xtype: 'gridcolumn',
dataIndex: 'date',
text: 'Three',
editor: {
xtype: 'combobox',
displayField: 'name',
valueField: 'id',
bind: {
store: '{threeStore}'
}
}
}
],
dockedItems: [
{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
text: 'Add',
listeners: {
click: 'onButtonClick'
}
}
]
}
],
plugins: [
{
ptype: 'cellediting',
clicksToEdit: 1
}
]
});
Ext.define('combo.view.MyGridPanelViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.mygridpanel',
requires: [
'Ext.data.Store',
'Ext.data.proxy.Memory'
],
stores: {
oneStore: {
model: 'combo.model.OneModel',
data: [
{
description: 'vel'
},
{
description: 'magni'
},
{
description: 'delectus'
},
{
description: 'quas'
},
{
description: 'asperiores'
},
{
description: 'molestias'
},
{
description: 'sunt'
},
{
description: 'facere'
},
{
description: 'et'
},
{
description: 'magnam'
}
],
proxy: {
type: 'memory'
}
},
twoStore: {
model: 'combo.model.TwoModel',
data: [
{
id: 'aperiam_01',
lastname: 'aut'
},
{
id: 'iure_11',
lastname: 'dolores'
},
{
id: 'fugiat_21',
lastname: 'excepturi'
},
{
id: 'et_31',
lastname: 'praesentium'
},
{
id: 'necessitatibus_41',
lastname: 'aperiam'
},
{
id: 'fugiat_51',
lastname: 'quia'
},
{
id: 'ullam_61',
lastname: 'nihil'
},
{
id: 'tempora_71',
lastname: 'nisi'
},
{
id: 'ea_81',
lastname: 'tempora'
},
{
id: 'doloribus_91',
lastname: 'nostrum'
}
],
proxy: {
type: 'memory'
}
},
threeStore: {
model: 'combo.model.ThreeModel',
data: [
{
id: 'sapiente_01',
name: 'dolorem'
},
{
id: 'eum_11',
name: 'animi'
},
{
id: 'rerum_21',
name: 'rerum'
},
{
id: 'earum_31',
name: 'quaerat'
},
{
id: 'voluptatem_41',
name: 'modi'
},
{
id: 'omnis_51',
name: 'autem'
},
{
id: 'autem_61',
name: 'autem'
},
{
id: 'voluptatem_71',
name: 'voluptatum'
},
{
id: 'ut_81',
name: 'pariatur'
},
{
id: 'dolore_91',
name: 'dolorem'
}
],
proxy: {
type: 'memory'
}
}
}
});
Ext.define('combo.view.MyGridPanelViewController', {
extend: 'Ext.app.ViewController',
alias: 'controller.mygridpanel',
onButtonClick: function(button, e, eOpts) {
button.up('grid').getStore().insert(0, {});
grid.getPlugin('CellEditing').startEditByPosition({row: 0, column: 1});
}
});
Ext.define('combo.model.OneModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: [
{
name: 'description'
}
]
});
Ext.define('combo.model.ThreeModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: [
{
name: 'id'
},
{
name: 'name'
}
]
});
Ext.define('combo.model.TwoModel', {
extend: 'Ext.data.Model',
requires: [
'Ext.data.field.Field'
],
fields: [
{
name: 'id'
},
{
name: 'lastname'
}
]
});
I want to create a button that when I click on it, it will set a renderer for a column on my grid. I'm looking through the API for columns http://docs.sencha.com/extjs/5.1/5.1.1-apidocs/#!/api/Ext.grid.column.Column
and I do not see a method that says setRenderer, how can I achieve this?
Edit: I do not want to set it when I create the column ( i know there is a property to set the renderer)
You could try simply changing the renderer, no need for a setRenderer
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields:[ 'name', 'email', 'phone'],
data: [
{ name: 'Lisa', email: 'lisa#simpsons.com', phone: '555-111-1224' },
{ name: 'Bart', email: 'bart#simpsons.com', phone: '555-222-1234' },
{ name: 'Homer', email: 'homer#simpsons.com', phone: '555-222-1244' },
{ name: 'Marge', email: 'marge#simpsons.com', phone: '555-222-1254' }
]
});
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name',
renderer: function (value) {
return value + ' Simpson';
}},
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
],
height: 400,
width: 400,
renderTo: Ext.getBody(),
bbar: [{
text: 'Change First Column Renderer',
handler: function(b) {
var grid = b.up('grid'),
columns = grid.getColumnManager().getColumns(),
column = columns[0];
column.renderer = function(value) {
return value === 'Lisa' ? 'L Simpson' : value;
}
grid.view.refreshView();
}
}]
});
Fiddle: https://fiddle.sencha.com/#fiddle/1a5e
I am using ExtJs 4.1 grid and have added group feature. In the store I have specified the groupField and grouping feature is working fine. But when the grid renders, the group header is shown as Group: Group-Name". How Can I prevent 'Group' keyword from appearing in the group header (which is highlighted on below image).
Ext.require(['Ext.data.*', 'Ext.grid.*']);
Ext.onReady(function() {
Ext.regModel('Teams', {
fields: ['name', 'sport']
});
var teamStore = new Ext.data.Store({
model: 'Teams',
sorters: ['sport','name'],
groupField: 'sport',
data: [
{ name: 'Aaron', sport: 'Table Tennis' },
{ name: 'Aaron', sport: 'Football' },
{ name: 'Abe', sport: 'Basketball' },
{ name: 'Tommy', sport: 'Football' },
{ name: 'Tommy', sport: 'Basketball' },
{ name: 'Jamie', sport: 'Table Tennis' },
{ name: 'Brian', sport: 'Basketball' },
{ name: 'Brian', sport: 'Table Tennis' }
]
});
var grid = new Ext.grid.GridPanel({
renderTo: Ext.getBody(),
store: teamStore,
width: 400,
height: 300,
title: 'Sports Teams',
features: [{
ftype: 'grouping'
}],
headers: [{
text: 'Name',
flex: 1,
dataIndex: 'name'
},{
text: 'Sport',
dataIndex: 'sport'
}]
});
});
features: [{
ftype: 'grouping',
groupHeaderTpl: '{name}'
}]