I've seen similar questions go unanswered elsewhere. I want to have a combobox in a column with two options (ASC, DEC) in it. I want it to show up in each row, or at least have its value show up when it's not selected.
I know that its not a 'good idea' to render a combobox in each row, but in this case I know I will have a maximum of about 20 rows, so it shouldn't be a huge deal. If this can't be done I want to have the selected value from the combobox show. Currently I just have the comboboxes appearing when I click a row, which doesn't make much sense since you can't see your selection unless you are making it. What is the solution to this?
Also, I want to get rid of the change and cancel buttons that pop up when I click a row, I just want to be able to edit the cell with the combobox, and have it automatically change/save.
You can set a default value for the combo.
That should then get that rendered at startup.
Use cell renderer to render the displayField of the combo into your grid. Following a working example that can be poster in one of the API code boxes.
Working JSFiddle
Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone', 'id'],
data: {
'items': [{
"name": "Lisa",
"email": "lisa#simpsons.com",
"phone": "555-111-1224",
"id": 0
}, {
"name": "Bart",
"email": "bart#simpsons.com",
"phone": "555-222-1234",
"id": 1
}, {
"name": "Homer",
"email": "home#simpsons.com",
"phone": "555-222-1244",
"id": 2
}, {
"name": "Marge",
"email": "marge#simpsons.com",
"phone": "555-222-1254",
"id": 3
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField));
};
}
// the combo store
var store = new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
[1, "Option 1"],
[2, "Option 2"]
]
});
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Name',
dataIndex: 'name',
editor: 'textfield'
}, {
header: 'Email',
dataIndex: 'email',
flex: 1,
editor: {
xtype: 'textfield',
allowBlank: false
}
}, {
header: 'Phone',
dataIndex: 'phone'
}, {
header: 'id',
dataIndex: 'id',
editor: combo,
renderer: comboBoxRenderer(combo)
}],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
{
header: 'Your header',
dataIndex: 'your Column',
editor: {
xtype: 'combobox',
store: yourStore,
queryMode: 'local',
displayField: 'Your Display..',
valueField: 'Your Value'
}
Related
I am wondering how to properly use reference in EXTJS views. More specifically, I would like to bind hidden property of one component to state of other component with given reference. For example, if a view contains a button and a combobox, how to bind hidden property of a button to isSelected state of a combobox.
Here is what I tried, but nothing works:
Ext.create('Ext.Panel',{
renderTo: Ext.getBody(),
width: 400,
height: 400,
viewModel: {},
items:[
{
xtype: 'combobox',
reference: 'myCombo',
label: 'Select',
queryMode: 'local',
name: 'myComb',
store: {
fields: ['value', 'name'],
data : [
{"value":"1", "name":"Name1"},
{"value":"2", "name":"Name2"},
{"value":"3", "name":"Name3"},
{"value":"4", "name":"Name4"},
{"value":"5", "name":"Name5"},
]
},
editable: false,
displayField: 'name',
valueField: 'value',
},
{
xtype: 'button',
text: 'myButton',
bind: {
//hidden: '{myCombo.getValue()?true:false}'
//hidden: (!!myCombo.getValue())
}
}
]
})
Just bind the view model data to combobox value, something like this:
Ext.create('Ext.Panel', {
renderTo: Ext.getBody(),
width: 400,
height: 400,
viewModel: {
data: {
comboboxSelectedValue: '',
}
},
items: [{
xtype: 'combobox',
reference: 'myCombo',
label: 'Select',
queryMode: 'local',
name: 'myComb',
store: {
fields: ['value', 'name'],
data: [{
"value": "",
"name": "Unselected"
}, {
"value": "1",
"name": "Name1"
}, {
"value": "2",
"name": "Name2"
}, {
"value": "3",
"name": "Name3"
}, {
"value": "4",
"name": "Name4"
}, {
"value": "5",
"name": "Name5"
}, ]
},
editable: false,
displayField: 'name',
valueField: 'value',
bind: {
value: '{comboboxSelectedValue}'
}
}, {
xtype: 'button',
text: 'myButton',
bind: {
hidden: '{!comboboxSelectedValue}'
}
}]
})
I have a grid with cellediting plugin.
One of my columns is a int field which represents a value in a combo store when editing the cell.
I want to know how can I have this column to show the displayfield instead of the value before I edit the cell.
Here are the images for reference:
The values 2,0,0 etc are my "accesstype" field that is an int.
If I click the cell to edit that why I get:
And If I select a value then instead of showing the text I get again the int value.
How can I show the display field instead of the value field?
For the ease of access here's the answer from the other question:
You can set a default value for the combo. That should then get that rendered at startup.
Use cell renderer to render the displayField of the combo into your grid. Following a working example that can be poster in one of the API code boxes
Working JSFiddle
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone', 'id'],
data:{'items':[
{"name":"Lisa", "email":"lisa#simpsons.com", "phone":"555-111-1224","id": 0},
{"name":"Bart", "email":"bart#simpsons.com", "phone":"555-222-1234","id": 1},
{"name":"Homer", "email":"home#simpsons.com", "phone":"555-222-1244","id": 2},
{"name":"Marge", "email":"marge#simpsons.com", "phone":"555-222-1254","id": 3}
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the combo store
var store = new Ext.data.SimpleStore({
fields: [ "value", "text" ],
data: [
[ 1, "Option 1" ],
[ 2, "Option 2" ]
]
});
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
Just remove the config property 'valueField' for that combo,it will display the displayField value after the select of the value from the dropdown.
Sorry I think this may be a duplicate. But I am not getting correct answer from anywhere. Please help me to find the issue.
I am creating a Ext Js grid with store. Also with the help of this blog
http://blog.jardalu.com/2013/6/21/grid-paging-extjs-sencha
I am creating Grid whcih loads Data Page for the first PAge. But when I press next, last, refresh no events are working. Also from the console am getting an error like this from ext js file
Uncaught TypeError: Cannot read property 'name' of undefined
Please help me to find the issue.
Code:-
/*global Ext:false */
Ext.require([
'Ext.data.*',
'Ext.grid.*'
]);
Ext.onReady(function () {
var itemsPerPage = 2; // set the number of items you want per page
var store = Ext.create('Ext.data.Store', {
id: 'simpsonsStore',
autoLoad: false,
fields: ['name', 'email', 'phone'],
pageSize: itemsPerPage,
data: {
'items': [{
'name': 'Lisa',
"email": "lisa#simpsons.com",
"phone": "555-111-1224"
}, {
'name': 'Bart',
"email": "bart#simpsons.com",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "home#simpsons.com",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "marge#simpsons.com",
"phone": "555-222-1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items',
totalProperty: 'total'
}
},
listeners : {
beforeload : function(store, operation, eOpts){
var page = operation.page;
var limit = operation.limit;
var dataResult = [];
var startPage = (page -1) * 2;
var totalCount = startPage + limit;
console.log(store.proxy.data);
for (var i = startPage; i < totalCount ; i++) {
dataResult.push(store.proxy.data.items[i]);
}
store.proxy.data.items = dataResult;
store.proxy.data.total = 4;
}
}
});
var TOTAL = 94; //random
// specify segment of data you want to load using params
store.loadPage(1);
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
columns: [{
header: 'Name',
dataIndex: 'name'
}, {
header: 'Email',
dataIndex: 'email',
flex: 1
}, {
header: 'Phone',
dataIndex: 'phone'
}],
width: 400,
height: 125,
dockedItems: [{
xtype: 'pagingtoolbar',
store: store, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
});
Please see the DEMO here :- http://jsfiddle.net/B6qBN/
I don't know your problem ( actually I tried to fix issue but didn't want to spent much time ). Here is the working sample. It seems to me, there is a data model problem.
Sencha Fiddle: Paging Toolbar
// Json File for demostration
{
"total": 5,
"userList":[
{"uid": "1", "firstName":"Tommy","lastName":"Maintz"},
{"uid": "2", "firstName":"Ed","lastName":"Spencer"},
{"uid": "3", "firstName":"Oğuz","lastName":"Çelikdemir"},
{"uid": "4", "firstName":"Jamie","lastName":"Avins"},
{"uid": "5", "firstName":"Dave","lastName":"Kaneda"}
]
}
// the following is code section
var itemsPerPage = 2; // set the number of items you want per page
Ext.onReady(function(){
Ext.define('senchatest.model.Contact', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'}
]
});
var UserList = new Ext.data.JsonStore ({
model: 'senchatest.model.Contact',
pageSize: itemsPerPage,
proxy: {
type: 'ajax',
url : 'contacts.json',
reader: {
type: 'json',
root: 'userList',
totalProperty: 'total'
}
}
});
UserList.load();
var users = Ext.create('Ext.form.Panel', {
bodyPadding: 10,
width: 300,
height: 400,
title: 'User List',
items: [
{
xtype: 'gridpanel',
store: UserList,
columns: [
{text: 'Name', dataIndex: 'firstName'},
{text: 'Surname', dataIndex: 'lastName'}
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: UserList, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}]
}
],
renderTo: Ext.getBody()
})
});
I have a dataview that gets loaded with a parameter. I render this data in a template. I am trying to use the same data in which there is a nested item to render to a grid.
The data looks like this:
{
"myJson": {
"name": "abc",
"type": "faulty",
"notes": [
{
"date": "01-01-1970",
"note": "test note"
},
{
"date": "01-02-1970",
"note": "test note 2"
}
]
}
}
The store:
proxy: {
type: 'ajax',
url: '/api/detail/',
reader: {
type: 'json',
root: 'myJson'
}
}
Model:
{
name:'name',
},
{
name:'type',
},
{
name:'notes',
mapping:'notes'
},
Template:
{name} - {type}
That all works. What I'd like to do is use the notes chunk to display in a grid. Problem is I can't get it to read the notes group.
var notesListView = new Ext.list.ListView({
store: 'myStore',
multiSelect: false,
width:'100%',
id:'notesList',
columns: [{
header: 'Date',
width: 75,
dataIndex: 'date'
},{
header: 'Note',
width: 150,
dataIndex: 'note',
}]
});
Is it even possible to do this? Or do I need to create a new store and model to use this group of data in a grid?
I've tried mapping to notes.date, for instance, in both the model
name:'note_date',
mapping:'notes.date'
and in the grid itself
dataIndex:'notes.date'
neither of which worked.
I've also tried using renderer but this doesn't work either as it's an array
renderer:function(value, metaData, record, rowIndex, colIndex, store){
var value = value.date;//won't work; it needs an index a la value[0].date
return value;
}
You could create a nested model with the same data you are receiving. It would be like this
Ext.define("JsonModel", {
extend: 'Ext.data.Model',
fields: ['name','type'],
hasMany: [{
model: 'Note',
name: 'notes'
}]
});
Ext.define("Note", {
extend: 'Ext.data.Model',
fields: [
'date',
'note']
});
This way you could access the children of any give record like this
var jsonRecordChildren = jsronRecord.notes()
The variable jsonRecordChildren that I just created is of the type Store, so you could easily assign it to the attribute store of a grid.
Ext.create('Ext.grid.Panel', {
store: selectedRecord.notes(),
columns: [
{ text: 'Date', dataIndex: 'date' },
{ text: 'Note', dataIndex: 'note'}
],
renderTo: Ext.getBody()
});
http://jsfiddle.net/alexrom7/rF8mt/2/
Just getting frustrated by something that should be an easy fix, but I'm too simple minded to see it :)
I'm having a grid where 1 column is a combobox. The thing works just fine and the correct value is beeing sent through my ajax request, but after I edited the grid row, the combobox disappread and the value that comes into place is not the label, but the value.
editor: new Ext.form.field.ComboBox({
typeAhead: true,
lazyRender: true,
store: new Ext.data.ArrayStore({
fields: ['contact', 'contactLabel'],
data: [
[1,'Jan'],
[2,'Jeroen'],
[3,'Mattijs'],
[4,'Sven'],
[5,'Thomas'],
[6,'Yoran']
]
}),
valueField: 'contact',
displayField: 'contactLabel',
hiddenName: 'contact'
})
So what happens is that when I change the combobox to i.e.. "Thomas", the value of the cell becomes "5", instead of "Thomas". I thought that defining value/display fields would make a difference, but it does not.
Anyone that knows the answer?
I am not quite sure if I got you right. If so you will need a renderer for that. I guess the example below the code snipped should show you if you are meaning such a case.
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
See this full working example for both (cellEditing + rowEditing) JSFiddle ()
Here's the complete code
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone', 'id'],
data:{'items':[
{"name":"Lisa", "email":"lisa#simpsons.com", "phone":"555-111-1224","id": 0},
{"name":"Bart", "email":"bart#simpsons.com", "phone":"555-222-1234","id": 1},
{"name":"Homer", "email":"home#simpsons.com", "phone":"555-222-1244","id": 2},
{"name":"Marge", "email":"marge#simpsons.com", "phone":"555-222-1254","id": 3}
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
// the combo store
var store = new Ext.data.SimpleStore({
fields: [ "value", "text" ],
data: [
[ 0, "Option 0" ],
[ 1, "Option 1" ],
[ 2, "Option 2" ],
[ 3, "Option 3" ]
]
});
// the renderer. You should define it within a namespace
var comboBoxRenderer = function(combo) {
return function(value) {
var idx = combo.store.find(combo.valueField, value);
var rec = combo.store.getAt(idx);
return (rec === null ? '' : rec.get(combo.displayField) );
};
}
// the edit combo
var combo = new Ext.form.ComboBox({
store: store,
valueField: "value",
displayField: "text"
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: 'cell'
});
// demogrid
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Name', dataIndex: 'name', editor: 'textfield'},
{header: 'Email', dataIndex: 'email', flex:1,
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{header: 'Phone', dataIndex: 'phone'},
{header: 'id', dataIndex: 'id', editor: combo, renderer: comboBoxRenderer(combo)}
],
selType: 'rowmodel',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
})
],
height: 200,
width: 400,
renderTo: 'row'
});
html
<div id="cell"></div>
<div id="row"></div>
Try:
data: [
{contact: 1, contactLabel: 'Jan'},
...
]