ExtJS Combobox Rowediting Not Displaying The Latest Value After Click Update - extjs

I got this one rowediting with combobox for my project. The value displayed in the rowediting is coming from DB, then user can edit the value in rowediting. I got problem when i edit the combobox in it. The combobox display back the previous value after I click Update. The other fields are okay. The backend side also okay if I submit the grid form. The only problem right now is the combobox display. Anyone have any idea on this? Thank you so much in advanced :)
Screenshot image:
This is my JS code:
items: [
{
xtype: 'grid',
name: 'prescriptionGrid',
reference: 'prescriptionGrid', flex: 1, height: 200, scrollable: true,
store: {
type: 'array' ,
fields: ['id',
'inventorycatid',
'stationid',
'route',
'frequency',
'dose',
'duration',
'medicationName',
'quantity']
},
listeners: {
validateedit: 'prescriptionGridItemValidate',
beforeedit: 'prescriptionbeforeedit',
},
columns: [
{ text: 'Max Request Quantity', hidden: true, dataIndex:'maxRequestQuantity' },
//{ text: 'Created By', hidden: true, dataIndex:'createdby', name: 'createdby', value: data.createdbyname, reference:'createdby',},
{ text: 'Medication Name',
dataIndex: 'inventorycatid',
flex: 4,
reference: 'medicationName',
renderer: 'showPrescriptionItem',
editor: {
xtype: 'combobox',
name: 'inventorycatid',
minChars: 0,
queryMode: 'remote',
queryParam: 'cbxname',
store: {
type: 'InventoryCat',
autoLoad: true,
remoteFilter: true,
filters: [{ property: 'typename', value: 'Inventory:Medicine' }],
},
/* remoteFilter: false, */
valueField: 'id',
displayField: 'name',
forceSelection: true,
editable: false,
allowBlank: false,
listeners: {
select: 'inventorycatComboSelected',
}
}
},
{ text: 'Route',
dataIndex: 'route',
flex: 2,
reference: 'route',
editor: {
xtype: 'combobox',
queryMode: 'local',
displayField: 'name',
valueField: 'name',
store: [
{ id: '250', name: 'Tab (Tablet)' },
{ id: '251', name: 'Caps (Capsule)' },
{ id: '252', name: 'Syrup' },
{ id: '253', name: 'IM (Intramuscular)' },
{ id: '254', name: 'IV (Intravenous)' },
{ id: '255', name: 'LA (Local Application)' },
{ id: '256', name: 'SL (Sublingual)' },
{ id: '257', name: 'SC (Subcutaneous)' },
],
editable: false,
name: 'route'
}
},
{ text: 'Dose',
dataIndex: 'dose',
flex: 1,
reference: 'dose',
editor: {
name: 'dose', allowBlank: false
}
},
{ text: 'Frequency',
dataIndex: 'frequency',
flex: 2,
reference: 'frequency',
editor: {
xtype: 'combobox',
queryMode: 'local',
displayField: 'name',
valueField: 'name',
store: [
{ id: '250', name: 'Daily' },
{ id: '251', name: 'Every other day ' },
{ id: '252', name: 'BD (2x a day)' },
{ id: '253', name: 'TDS (3x a day) ' },
{ id: '254', name: 'QID (4x a day)' },
{ id: '255', name: 'Q4h (Every 4 hrs)' },
{ id: '256', name: 'Q4h-6h (Every 4 to 6 hrs) ' },
{ id: '257', name: 'qwk (every week)' },
],
name: 'frequency', allowBlank: true
}
},
{ text: 'Duration',
dataIndex: 'duration',
flex: 1,
reference: 'duration',
editor: {
name: 'duration', allowBlank: false
}
},
{
text: 'Quantity',
dataIndex: 'quantity',
flex: 1,
reference: 'quantity',
editor: {
name: 'quantity', allowBlank: false
}
}
],
selType: 'rowmodel',
plugins: [
{ ptype: 'rowediting', id: 'rowEditPlugin', clicksToMoveEditor: 1, autoCancel: false,
}
]
},
],
And here is my ControllerJS:
showPrescriptionItem: function(value, metaData, record, rowIndex, colIndex, store, view) {
console.log(record.data, "ShowPrescription"); //After edit, capture correct inventorycat but wrong medicationName
// console.log(value, "ShowPrescription2");
return record.get('medicationName') || this.getViewModel().get('inventoryMap')[value];
},
inventorycatComboSelected: function(combo, record) {
var vm = this.getViewModel(),
map = vm.get('inventoryMap');
map[record.id] = record.data.name;
vm.set('inventoryMap', map);
console.log(record.data, "InventorycatSelected"); //After edit, capture correct id & name
//return(map);
// var itemRecord = combo.up('editor').context.record;
},
prescriptionGridItemValidate: function(editor, e) {
rowIndex = e.rowIdx;
var itemid = editor.editor.form.findField('inventorycatid').getValue();
var unit = editor.editor.form.findField('quantity').getValue();
if(!Ext.isNumeric(unit)) {
Ext.Msg.alert('Error', 'Quantity must be in numeric');
e.cancel = true;
}
else if(parseInt(unit) < 0) {
Ext.Msg.alert('Error', 'The quantity has to be 0 or more');
e.cancel = true;
}
else {
e.cancel = false;
}
console.log(e.newValues,'context')
},
prescriptionbeforeedit: function(elemnt,cell){
if (cell.record.data.inventorycatid != ''){
elemnt.editor.form.getFields().items[0].setDisabled(true)
elemnt.editor.form.getFields().items[0].setRawValue(cell.row.cells[0].textContent)
} else {
elemnt.editor.form.getFields().items[0].setDisabled(false)
}
},

Tq for ur respond. I have fixed this issue before. I changed my renderer code as below & it works:
showPrescriptionItem: function(value, metaData, record, rowIndex, colIndex, store, view) {
var map = this.getView().getViewModel().get('inventoryMap');
var medicationName = record.get('medicationName');
//console.log(map[value], 'map value');
if(medicationName !== '' && map[value] == undefined) {
console.log(medicationName, "ShowPrescriptionOldVal");
return medicationName;
}
else {
console.log(map[value], "ShowPrescriptionNewVal");
return map[value];
}
}

Related

Avoid the grid cell to get dirty unless the values is changed

How to avoid the grid cell from become a dirty cell unless the value is changed,
when I just touch the time cell , it becomes a dirty cell, how do I avoid that being getting dirty,
here's the Fiddle
Here is my grid ,
Ext.application({
name: 'Fiddle',
launch: function () {
var myStore = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['busname', 'time', 'typebus',],
data: [{
busname: 'ABCD',
time: '15:30:00',
typebus: 'AC Volvo',
}, {
busname: 'aaa',
time: '13:30:00',
typebus: 'Seater',
}, {
busname: 'AAAA',
time: '18:30:00',
typebus: 'Sleeper',
}, {
busname: 'ABCD',
time: '19:30:00',
typebus: 'AC Volvo',
},]
});
var typebusStore = Ext.create('Ext.data.Store', {
storeId: 'typeBusStore',
fields: ['id', 'name'],
data: [{
id: 1,
name: 'AC Volvo'
}, {
id: 2,
name: 'Seater'
}, {
id: 3,
name: 'Sleeper'
}]
})
Ext.create('Ext.grid.Panel', {
xtype: 'gridpanel',
itemId: 'busTimegrid',
pageSize: 1,
title: 'BUS DEATILS',
mapperId: 'getBusTime',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Bus Name',
dataIndex: 'busname',
editor: 'textfield'
}, {
text: 'Bus Time',
dataIndex: 'time',
xtype: 'gridcolumn',
renderer: function (value) {
if (value instanceof Date)
return Ext.util.Format.date(value, 'H:i:s');
else
return value;
},
flex: 1,
editor: {
xtype: 'timefield',
format: 'H:i:s',
allowBlank: true,
maskRe: /[0-9,:]/,
listeners: {
beforeselect: function (timefield, record) {
var grid = timefield.up('grid');
if (grid.store.find('time', record.data.disp) != -1) {
Ext.Msg.alert("Bus time already exist.");
return false;
}
}
}
}
}, {
header: 'Bus TYpe',
dataIndex: 'typebus',
editable: true,
renderer: function (value) {
if (value !== null && value.length == 1) {
var store = this.getEditor().getStore();
return store.findRecord('id', value).get('name');
}
return value;
},
editor: {
xtype: 'combo',
displayField: 'name',
valueField: 'id',
editable: true,
}
}],
selModel: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
},
height: 200,
width: 400,
dockedItems: [{
xtype: 'toolbar',
docked: 'bottom',
items: [{
xtype: 'button',
flex: 1,
text: 'Download to Excel',
handler: function(b, e) {
b.up('grid').downloadExcelXml();
}
}]
}
],
renderTo: Ext.getBody()
});
}
});
Try this way - Fiddle
Ext.application({
name: 'Fiddle',
launch: function() {
run();
window.show();
}
});
function run() {
var myStore = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: [{
name: 'busname',
type: 'string'
}, {
name: 'time',
type: 'date'
}, {
name: 'typebus',
type: 'string'
}],
pageSize: 2,
proxy: {
type: 'memory',
enablePaging: true
},
data: [{
busname: 'ABCD',
time: '2016-03-03 15:30:00',
typebus: 'AC Volvo',
}, {
busname: 'aaa',
time: '2016-03-03 13:30:00',
typebus: 'Seater',
}, {
busname: 'AAAA',
time: '2016-03-03 18:30:00',
typebus: 'Sleeper',
}, {
busname: 'ABCD',
time: '2016-03-03 19:30:00',
typebus: 'AC Volvo',
}, ]
});
var typebusStore = Ext.create('Ext.data.Store', {
storeId: 'typeBusStore',
fields: ['id', 'name'],
data: [{
id: 1,
name: 'AC Volvo'
}, {
id: 2,
name: 'Seater'
}, {
id: 3,
name: 'Sleeper'
}]
})
Ext.create('Ext.grid.Panel', {
xtype: 'gridpanel',
itemId: 'busTimegrid',
pageSize: 1,
title: 'BUS DEATILS',
mapperId: 'getBusTime',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Bus Name',
dataIndex: 'busname',
editor: 'textfield'
}, {
xtype: 'datecolumn',
text: 'Bus Time',
dataIndex: 'time',
format: 'H:i:s',
flex: 1,
renderer: function(value) {
return Ext.util.Format.date(value, 'H:i:s');
},
editor: {
xtype: 'timefield',
format: 'H:i:s',
allowBlank: true,
maskRe: /[0-9,:]/
}
}, {
header: 'Bus TYpe',
dataIndex: 'typebus',
editable: true,
renderer: function(value, md, record) {
var retValue = Array();
if (Ext.isArray(value)) {
Ext.each(value, function(id) {
var ename = Ext.data.StoreManager.lookup('typeBusStore').findRecord('id', id).get('name');
retValue.push(ename);
console.log(retValue);
});
}
if (retValue.length > 0) {
return retValue.join(", ");
}
return value;
},
editor: {
xtype: 'combo',
displayField: 'name',
valueField: 'id',
editable: true,
forceSelection: true,
multiSelect: true,
displayTpl: '<tpl for=".">' +
'{name}' +
'<tpl if="xindex < xcount">, </tpl>' +
'</tpl>',
store: typebusStore
}
}],
selModel: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
},
height: 200,
width: 400,
dockedItems: [{
xtype: 'pagingtoolbar',
store: myStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
}

MultiSelect in extjs Combobox

I'm trying to multiselect in combobox of the Extjs, After I select the Items , the tpl index is rendered , want to render the value that's the displayfield selected when away out from the cell, how can I be able to Achieve this.
here's the code
function run() {
var myStore=Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['busname', 'time', 'typebus',],
pageSize:2,
proxy: {
type: 'memory',
enablePaging: true
},
data: [{
busname: 'ABCD',
time: '15:30:00',
typebus: 'AC Volvo',
}, {
busname: 'aaa',
time: '13:30:00',
typebus: 'Seater',
},{
busname: 'AAAA',
time: '18:30:00',
typebus: 'Sleeper',
},{
busname: 'ABCD',
time: '19:30:00',
typebus: 'AC Volvo',
},]
});
Ext.create('Ext.grid.Panel', {
xtype :'gridpanel',
itemId:'busTimegrid',
pageSize:1,
title: 'BUS DEATILS',
mapperId:'getBusTime',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Bus Name',
dataIndex: 'busname',
editor: 'textfield'
}, {
text: 'Bus Time',
dataIndex: 'time',
xtype: 'gridcolumn',
renderer: function (value) {
if (value instanceof Date)
         return Ext.util.Format.date(value, 'H:i:s');
     else
     return value;
},
flex: 1,
editor: {
xtype: 'timefield',
format: 'H:i:s',
allowBlank: true,
maskRe: /[0-9,:]/,
listeners: {
beforeselect: function(timefield, record) {
var grid = timefield.up('grid');
if(grid.store.find('time', record.data.disp) != -1) {
Ext.Msg.alert("Bus time already exist.");
return false;
}
}
}
}
}, {
header: 'Bus TYpe',
dataIndex: 'typebus',
editable:true,
renderer: function (value) {
if (Ext.isNumber(value)) {
var store = this.getEditor().getStore();
return store.findRecord('id', value).get('name');
}
return value;
},
editor: {
xtype: 'combo',
displayField: 'name',
valueField: 'id',
editable:true,
forceSelection:true,
multiSelect: true,
displayTpl: '<tpl for=".">' +
'{name}' +
'<tpl if="xindex < xcount">, </tpl>' +
'</tpl>',
store: Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
data: [{
id: 1,
name: 'AC Volvo'
}, {
id: 2,
name: 'Seater'
}, {
id: 3,
name: 'Sleeper'
}]
})
}
}],
selModel: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
},
listners: [{
fn: 'onUsernamefieldBlur',
event: 'blur',
delegate: 'busname'
}],
onUsernamefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Busname can't be empty");
textfield.setFocus(true);
}
},
height: 200,
width: 400,
dockedItems: [{
xtype: 'pagingtoolbar',
store: myStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
var gridRow = myStore.getModifiedRecords();
Ext.each(gridRows, function (gridRow) {
var dirtyInd = myStore.indexOf(gridRow);
var newTime = new Date(store.getAt(dirtyInd).data.time);
},
myStore.each(function (record, idx) {
var newT = new Date(record.get('time'));
if (Ext.Date.diff(newTime, newT,Ext.Date.SECOND)=== 0)
{
samebustime = true;
}
}));
if(samebustime){
Ext.Msg.alert('Warning','Same time occured')
}
}
Fiddle
I have done some modification to your original source code. You might like it or not. But in this code you get what you have asked for. I am not sure if that is exactly what you want.
Ext.application({
name: 'Fiddle',
launch: function () {
run();
window.show();
}
});
function run() {
var myStore = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['busname', 'time', 'typebus',],
pageSize: 2,
proxy: {
type: 'memory',
enablePaging: true
},
data: [{
busname: 'ABCD',
time: '15:30:00',
typebus: 'AC Volvo',
}, {
busname: 'aaa',
time: '13:30:00',
typebus: 'Seater',
}, {
busname: 'AAAA',
time: '18:30:00',
typebus: 'Sleeper',
}, {
busname: 'ABCD',
time: '19:30:00',
typebus: 'AC Volvo',
},]
});
var typebusStore = Ext.create('Ext.data.Store', {
storeId: 'typeBusStore',
fields: ['id', 'name'],
data: [{
id: 1,
name: 'AC Volvo'
}, {
id: 2,
name: 'Seater'
}, {
id: 3,
name: 'Sleeper'
}]
})
Ext.create('Ext.grid.Panel', {
xtype: 'gridpanel',
itemId: 'busTimegrid',
pageSize: 1,
title: 'BUS DEATILS',
mapperId: 'getBusTime',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Bus Name',
dataIndex: 'busname',
editor: 'textfield'
}, {
text: 'Bus Time',
dataIndex: 'time',
xtype: 'gridcolumn',
renderer: function (value) {
if (value instanceof Date)
return Ext.util.Format.date(value, 'H:i:s');
else
return value;
},
flex: 1,
editor: {
xtype: 'timefield',
format: 'H:i:s',
allowBlank: true,
maskRe: /[0-9,:]/,
listeners: {
beforeselect: function (timefield, record) {
var grid = timefield.up('grid');
if (grid.store.find('time', record.data.disp) != -1) {
Ext.Msg.alert("Bus time already exist.");
return false;
}
}
}
}
}, {
header: 'Bus TYpe',
dataIndex: 'typebus',
editable: true,
renderer: function (value, md, record) {
var retValue = Array();
if (Ext.isArray(value)) {
Ext.each(value, function(id) {
retValue.push(Ext.data.StoreManager.lookup('typeBusStore').findRecord('id', id).get('name'));
});
}
if (retValue.length > 0) {
return retValue.join(", ");
}
return value;
},
editor: {
xtype: 'combo',
displayField: 'name',
valueField: 'id',
editable: true,
forceSelection: true,
multiSelect: true,
displayTpl: '<tpl for=".">' +
'{name}' +
'<tpl if="xindex < xcount">, </tpl>' +
'</tpl>',
store: typebusStore
}
}],
selModel: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
},
listners: [{
fn: 'onUsernamefieldBlur',
event: 'blur',
delegate: 'busname'
}],
onUsernamefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Busname can't be empty");
textfield.setFocus(true);
}
},
height: 200,
width: 400,
dockedItems: [{
xtype: 'pagingtoolbar',
store: myStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
var gridRows = myStore.getModifiedRecords();
console.log(gridRows)
var samebustime = false;
Ext.each(gridRows, function (gridRow) {
var dirtyInd = myStore.indexOf(gridRow);
var newTime = new Date(store.getAt(dirtyInd).data.time);
myStore.each(function (record, idx) {
var newT = new Date(record.get('time'));
if (Ext.Date.diff(newTime, newT, Ext.Date.SECOND) === 0) {
samebustime = true;
}
})
});
if (samebustime) {
Ext.Msg.alert('Warning', 'Same time occured')
}
}
Fiddle

PageSize not working on Grid in ExtJS

I want to limit the records per page to a specific number apply paging in the grid but its failing due to some reason.
Can anyone say why it's failing, or not working? Here's the Fiddle.
My Store
var myStore=Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['busname', 'time', 'typebus',],
pageSize:2,
data: [{
busname: 'ABCD',
time: '15:30:00',
typebus: 'AC Volvo',
}, {
busname: 'aaa',
time: '13:30:00',
typebus: 'Seater',
},{
busname: 'AAAA',
time: '18:30:00',
typebus: 'Sleeper',
},{
busname: 'ABCD',
time: '19:30:00',
typebus: 'AC Volvo',
},]
Grid panel
Ext.create('Ext.grid.Panel', {
xtype :'gridpanel',
itemId:'busTimegrid',
pageSize:1,
title: 'BUS DEATILS',
mapperId:'getBusTime',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Bus Name',
dataIndex: 'busname',
editor: 'textfield'
}, {
text: 'Bus Time',
dataIndex: 'time',
xtype: 'gridcolumn',
renderer: function (value) {
if (value instanceof Date)
         return Ext.util.Format.date(value, 'H:i:s');
     else
     return value;
},
flex: 1,
editor: {
xtype: 'timefield',
format: 'H:i:s',
allowBlank: true,
maskRe: /[0-9,:]/,
}
}, {
header: 'Bus TYpe',
dataIndex: 'typebus',
editable:true,
renderer: function (value) {
if (Ext.isNumber(value)) {
var store = this.getEditor().getStore();
return store.findRecord('id', value).get('name');
}
return value;
},
editor: {
xtype: 'combo',
displayField: 'name',
valueField: 'id',
editable:true,
forceSelection:true,
store: Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
data: [{
id: 1,
name: 'AC Volvo'
}, {
id: 2,
name: 'Seater'
}, {
id: 3,
name: 'Sleeper'
}]
})
}
}],
selModel: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
},
listners: [{
fn: 'onUsernamefieldBlur',
event: 'blur',
delegate: 'busname'
}],
onUsernamefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Busname can't be empty");
textfield.setFocus(true);
}
},
height: 200,
width: 400,
dockedItems: [{
xtype: 'pagingtoolbar',
store: myStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
Added the pageSize but still the paging is not working. I don't seem to find out what's the issue. How can I find out the exact thing I'm missing?
From your question I observed you want to achieve local pagination which is different from actual pagination. To do this first you need to mention memory proxy and enable the pagination , Put my below code in your store.
proxy: {
type: 'memory',
enablePaging: true
}
I am able to get the pagination by putting the above proxy in your fiddle.
(Posted on behalf of the OP).
This worked fine, after I followed what Surya prakash suggested a solution.
Ext.application({
name: 'Fiddle',
launch: function () {
run();
window.show();
}
});
function run() {
var myStore=Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['busname', 'time', 'typebus',],
pageSize:2,
proxy: {
type: 'memory',
enablePaging: true
},
data: [{
busname: 'ABCD',
time: '15:30:00',
typebus: 'AC Volvo',
}, {
busname: 'aaa',
time: '13:30:00',
typebus: 'Seater',
},{
busname: 'AAAA',
time: '18:30:00',
typebus: 'Sleeper',
},{
busname: 'ABCD',
time: '19:30:00',
typebus: 'AC Volvo',
},]
});
Ext.create('Ext.grid.Panel', {
xtype :'gridpanel',
itemId:'busTimegrid',
pageSize:1,
title: 'BUS DEATILS',
mapperId:'getBusTime',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
header: 'Bus Name',
dataIndex: 'busname',
editor: 'textfield'
}, {
text: 'Bus Time',
dataIndex: 'time',
xtype: 'gridcolumn',
renderer: function (value) {
if (value instanceof Date)
return Ext.util.Format.date(value, 'H:i:s');
else
return value;
},
flex: 1,
editor: {
xtype: 'timefield',
format: 'H:i:s',
allowBlank: true,
maskRe: /[0-9,:]/,
}
}, {
header: 'Bus TYpe',
dataIndex: 'typebus',
editable:true,
renderer: function (value) {
if (Ext.isNumber(value)) {
var store = this.getEditor().getStore();
return store.findRecord('id', value).get('name');
}
return value;
},
editor: {
xtype: 'combo',
displayField: 'name',
valueField: 'id',
editable:true,
forceSelection:true,
store: Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
data: [{
id: 1,
name: 'AC Volvo'
}, {
id: 2,
name: 'Seater'
}, {
id: 3,
name: 'Sleeper'
}]
})
}
}],
selModel: 'cellmodel',
plugins: {
ptype: 'cellediting',
clicksToEdit: 1,
},
listners: [{
fn: 'onUsernamefieldBlur',
event: 'blur',
delegate: 'busname'
}],
onUsernamefieldBlur: function (textfield, e, eOpts) {
if (textfield.getValue() === '') {
Ext.Msg.alert("Busname can't be empty");
textfield.setFocus(true);
}
},
height: 200,
width: 400,
dockedItems: [{
xtype: 'pagingtoolbar',
store: myStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}],
renderTo: Ext.getBody()
});
}

rally set default value for combo box

I have a combobox for State that successfully filters in Rally. The code below works. I want to add an enhancement and have the combobox default to 'In Progress'. I added defaultValue but it has no effect. Thanks for your help.
Rally.onReady(function() {
Ext.define('Rally.example.CustomStoreGrid', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
Ext.create('Rally.data.wsapi.Store', {
model: 'defect',
autoLoad: true,
limit: 1000,
pageSize: 1000,
listeners: {
load: this._onDataLoaded,
scope: this
},
fetch: ['FormattedID', 'Name', 'Severity', 'State', 'InProgressDate', 'c_PlannedDeliveryVersion']
});
},
_onSelect: function() {
var grid = this.down('rallygrid'), store = grid.getStore();
store.clearFilter(true);
store.filter(this._getStateFilter());
},
_getStateFilter: function() {
return {
property: 'State',
operator: '=',
defaultValue: 'In Progress',
value: this.down('#priorityComboBox').getValue()
};
},
_onDataLoaded: function(store, data) {
var records = _.map(data, function(record) {
//Perform custom actions with the data here
//Calculations, etc.
return Ext.apply({
// Age: Math.round(((new Date() - record.get('InProgressDate')) / 86400000) * 10) / 10;
}, record.getData());
});
this.add({
xtype: 'rallyfieldvaluecombobox',
itemId: 'priorityComboBox',
fieldLabel: 'Filter by State:',
model: 'defect',
// multiSelect: true,
field: 'State',
listeners: {
select: this._onSelect,
// ready: this._onLoad,
scope: this
}
});
this.add({
xtype: 'rallygrid',
showPagingToolbar: false,
showRowActionsColumn: false,
editable: false,
store: Ext.create('Rally.data.custom.Store', {
limit: 1000,
pageSize: 1000,
data: records
}),
columnCfgs: [
{
xtype: 'templatecolumn',
text: 'ID',
dataIndex: 'FormattedID',
width: 100,
tpl: Ext.create('Rally.ui.renderer.template.FormattedIDTemplate')
},
{
text: 'Name',
dataIndex: 'Name',
flex: 1
},
{
text: 'Severity',
dataIndex: 'Severity'
},
{
text: 'State',
dataIndex: 'State'
},
{
text: 'Planned Delivery Version',
dataIndex: 'c_PlannedDeliveryVersion',
flex: 0.25
},
{
text: 'In Progress Date',
dataIndex: 'InProgressDate',
xtype: 'datecolumn',
format:'Y-m-d'
},
{
text: 'Age',
dataIndex: 'InProgressDate'
,
renderer: function(value) {
return Math.round(((new Date() - value) / 86400000) * 10) / 10;
}
}
]
});
}
});
Rally.launchApp('Rally.example.CustomStoreGrid', {
name: 'Custom Store Grid Example'
});
});
Using value config property sets the default value:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
items:{ html:'App SDK 2.0rc3 Docs'},
launch: function() {
this.add({
xtype: 'rallyfieldvaluecombobox',
model: 'UserStory',
field: 'ScheduleState',
value: 'In-Progress'
});
}
});

Use MVC to manage grid column events

I have a grid with some columns(combobox columns) which I need to manage their change events. I want to do it from a controller. The goal is to send the server the selected combo id when i need to insert or update the row and update the other columns depending of the value of this selected combo. Could you give me an example how I much do this?
I have 2 hidden columns which must be updated when the Combo Empresa and Camion changes with the id.
This is my grid def:
{
xtype: 'gridpanel',
id: 'grdListaFichaEmbarques',
minWidth: 1024,
autoScroll: true,
title: 'Listado de Fichas',
store: 'ListaFichasTransporte',
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {
pluginId: 'ListaFEPlugin'
})
],
columns: [
{
xtype: 'numbercolumn',
dataIndex: 'NumEmbarque',
text: 'NumEmbarque'
},
{
xtype: 'gridcolumn',
dataIndex: 'Empresa',
text: 'Empresa',
editor: {
xtype: 'combobox',
allowBlank: false,
displayField: 'Nombre',
hiddenName: 'Id',
store: 'ListaEmpresa',
valueField: 'Id'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'Contacto',
text: 'Contacto'
},
{
xtype: 'gridcolumn',
dataIndex: 'Celular',
text: 'Celular'
},
{
xtype: 'gridcolumn',
dataIndex: 'Placa1',
text: 'Placa1',
editor: {
xtype: 'combobox',
allowBlank: false,
displayField: 'Placa1',
store: 'ListaCamiones',
valueField: 'Id'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'Placa2',
text: 'Placa2'
},
{
xtype: 'gridcolumn',
dataIndex: 'Capacidad',
text: 'Capacidad'
},
{
xtype: 'gridcolumn',
dataIndex: 'Chofer',
text: 'Chofer'
},
{
xtype: 'gridcolumn',
dataIndex: 'Nextel',
text: 'Nextel'
},
{
xtype: 'gridcolumn',
dataIndex: 'CelularPeru',
text: 'CelularPeru'
},
{
xtype: 'gridcolumn',
dataIndex: 'CelularEcuador',
text: 'CelularEcuador'
},
{
xtype: 'gridcolumn',
dataIndex: 'Termoregistro1',
text: 'Termoregistro1'
},
{
xtype: 'gridcolumn',
dataIndex: 'Termoregistro2',
text: 'Termoregistro2'
},
{
xtype: 'gridcolumn',
dataIndex: 'PuntoRecojo',
text: 'PuntoRecojo',
editor: {
xtype: 'combobox',
displayField: 'Nombre',
store: 'ListaOrigenDestino',
valueField: 'Id'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraLlegadaOrigen',
text: 'FechaHoraLlegadaOrigen',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraDespachoOrigen',
text: 'FechaHoraDespachoOrigen',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraLlegadaTumbes',
text: 'FechaHoraLlegadaTumbes',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'gridcolumn',
dataIndex: 'PuntoLlegadaEcuador',
text: 'PuntoLlegadaEcuador',
editor: {
xtype: 'combobox',
displayField: 'Nombre',
store: 'ListaOrigenDestino',
valueField: 'Id'
}
},
{
xtype: 'datecolumn',
dataIndex: 'FechaHoraLLegadaDestinoEcuador',
text: 'FechaHoraLLegadaDestinoEcuador',
editor: {
xtype: 'datefield',
format: 'd/m/Y h:i:s',
submitFormat: 'd/m/Y h:i:s'
}
},
{
xtype: 'numbercolumn',
hidden: true,
dataIndex: 'IdEmpresa',
text: 'IdEmpresa'
},
{
xtype: 'numbercolumn',
hidden: true,
dataIndex: 'IdCamion',
text: 'IdCamion'
}
]
}
This is my Controller:
Ext.define('Fplweb2.controller.FichaEmbarque', {
extend: 'Ext.app.Controller',
refs: [
{
ref: 'GrillaFE',
selector: 'grid[id=grdListaFichaEmbarques]',
xtype: 'Ext.grid.Panel'
}
],
onButtonClick: function(button, e, eOpts) {
this.save();
},
onComboboxSelect: function(combo, records, eOpts) {
var grid = this.getGrillaFE();
var store = grid.getStore();
//HERE I WAS TRYING TO UPDATE THE COLUMNS
if( grid.getSelectionModel().hasSelection() )
{
var row = grid.getSelectionModel().getSelection();
var srow;
for(var i=0; i<store.count(); i++)
{
srow = store.getAt(i);
if(srow.get('NumEmbarque') == row[0].data.NumEmbarque)
{
console.log("ASIGNARA");
srow.IdEmpresa = records[0].data.Id;
srow.Contacto = records[0].data.Contacto;
srow.Celular = records[0].data.Celular;
}
}
}
},
init: function(application) {
this.listen({
controller: {},
component: {
'grid[xtype=gridpanel]': {
edit: this.save,
canceledit: this.cancel
}
});
this.control({
"button[id=btnFichaEmbarqueAgregar]": {
click: this.onButtonClick
},
"combobox[id=cmbGrdListaFichaEmbarquesEmpresa]": {
select: this.onComboboxSelect
}
});
},
save: function() {
var fechaact = new Date();
var grid = this.getGrillaFE();
var plugin = grid.editingPlugin;
var store = grid.getStore();
//SET THE FIRTS COMBO VALUE
//Combo Lista Empresas
var lestore = Ext.data.StoreManager.lookup('ListaEmpresa').getAt(0).get('Nombre');
//Combo Lista Origen - Destino
var odstore = Ext.data.StoreManager.lookup('ListaOrigenDestino').getAt(0).get('Nombre');
//Combo Lista Camiones
var lcstore = Ext.data.StoreManager.lookup('ListaCamiones').getAt(0).get('Placa1');
plugin.cancelEdit();
var r = Ext.create('Fplweb2.model.ListaFichasTransporte', {
NumEmbarque: store.getCount() + 1,
Empresa: lestore,
Contacto: 'Nuevo Contacto',
Celular: '999999999',
Placa1: lcstore,
Placa2: '',
Capacidad: '',
Chofer: 'Nuevo Chofer',
Nextel: '999999999',
CelularPeru: '999999999',
CelularEcuador: '999999999',
Termoregistro1: '',
Termoregistro2: '',
PuntoRecojo: odstore,
FHTranspPuntoRecojo: fechaact,
FHDespaPuntoRecojo: fechaact,
FHLlegadaTumbes: fechaact,
PuntoLlegadaEcuador: odstore,
FHLlegadaPuntoEcuador: fechaact
});
store.insert(0, r);
plugin.startEdit(0, 0);
store.sync();
},
cancel: function(editor, context, eOpts) {
console.log("cancelo");
var grid = this.getGrillaFE();
var plugin = grid.editingPlugin;
var store = grid.getStore();
plugin.cancelEdit();
store.removeAt(0);
if( context.record.phantom ) {
context.store.remove( context.record );
}
}
});
I want to do this FROM a controller.
Thanks in advance...
You need to catch the edit event of the grid (added by the editing plugin):
listeners: {
edit: function(editor, e) {
if (e.field === 'Empresa') {
// do a trip to the server if needed
// or update your column locally
e.record.set('IdCamion', e.value);
}
}
}

Resources