iwarner
24 Mar 2010, 2:53 AM
Hi
Ok so when I edit my row in the grid with Roweditor - the combobox immediately shows the valuefield - which is simply an ID and not the display field the user selected from
I have done quite a bit of searching - either the topics are very general or there are no signs of guidance
I was also looking to see if the ExtJS support a kind of callback - ie the JSON is submitted in the Success message there is JSON to overwrite the fields with fresh data. I though I read something that this was possible but see no help on this anywhere
The last thing to try I suppose would be to capture the update listener of the row editor and force the correct text into the row instead of the valuefield ID number.
Open to suggestions please
Included the code for this
Ext.BLANK_IMAGE_URL = 'http://extjs.cachefly.net/ext-3.0.0/resources/images/default/s.gif';
Ext.onReady(function()
{
// Instantiate the quick tips
Ext.QuickTips.init();
var xg = Ext.grid;
// Use RowEditor for editing
var rowEditor = new Ext.ux.grid.RowEditor({
errorSummary : false,
saveText : 'Update'
});
var msg = function(title, msg) {
Ext.Msg.show({
buttons : Ext.Msg.OK,
icon : Ext.Msg.INFO,
msg : msg,
minWidth : 200,
modal : true,
msg : msg,
title : title
});
};
// Display or bring forth the form
function uploadFormWindow()
{
if (!uploadCreateWindow.isVisible()) {
uploadCreateWindow.show();
} else {
uploadCreateWindow.toFront();
}
}
// Method to display negative numbers in a different colour
function renderNegativeAmount(val)
{
if (val < 0) {
var className = 'style="color: red"';
} else {
var className = 'style="font-weight: bold"';
}
return '<span ' + className + '>' + val + '</span>';
}
function renderVatLink(val, p, record)
{
return('<a id="myClickableField" href="/restaccounts/data/vatID/' + record.data.id + '" title="VAT Records">' + val + '</a>');
}
function reload()
{
store.baseParams.vatID = null;
store.reload({
params: {
start:0, limit:50, sort:'date', dir:'DESC'
}
});
}
// The DataWriter component.
var writer = new Ext.data.JsonWriter({
encode : false,
writeAllFields : true
});
// Create the data store
var store = new Ext.data.JsonStore({
fields : [
{ name: 'id', type: 'int' },
{ name: 'date', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'reference', type: 'string' },
{ name: 'invoice', type: 'string' },
{ name: 'payment', type: 'string' },
{ name: 'vat', type: 'int' }
],
idProperty : 'id',
messageProperty : 'data',
remoteSort : true,
restful : true,
root : 'data',
successProperty : 'success',
totalProperty : 'totalCount',
url : '/restaccounts',
writer : writer
});
// Create the Reference data store
var storeReference = new Ext.data.JsonStore({
fields : [
{ name : 'id', type: 'int' },
{ name : 'reference', type: 'string' }
],
root : 'data',
url : '/accounts/reference'
});
store.setDefaultSort('date', 'DESC');
store.load({params:{start:0, limit:50, sort:'date', dir:'DESC'}});
// Row expander
var expander = new Ext.grid.RowExpander({
expandOnDblClick : false,
tpl : new Ext.Template(
'<p style="margin-left: 50px; width: 99%; padding: 10px;"><b>Notes:</b> {description}</p>'
)
});
// create the column model
var columns = [
new xg.RowNumberer(),
expander,
{ header: 'Date', sortable: true, dataIndex: 'date' },
{ header: 'Reference', sortable: true, dataIndex: 'reference',
editor : {
allowBlank : false,
displayField : 'reference',
emptyText : 'Select Reference',
fieldLabel : 'Reference',
forceSelection : true,
lazyRender : true,
mode : 'remote',
name : 'reference',
store : storeReference,
typeAhead : true,
triggerAction : 'all',
valueField : 'id',
xtype : 'combo'
}
},
{ header: 'Invoice', sortable: true, dataIndex: 'invoice',
editor: {
xtype : 'textfield'
}
},
{ header: 'Payment', sortable: true, dataIndex: 'payment', renderer: renderNegativeAmount },
{ header: 'VAT', sortable: true, dataIndex: 'vat', renderer: renderVatLink,
editor : {
maxValue : 100,
minValue : 1,
xtype : 'numberfield'
}
}
];
// Create the pager
var pagingBar = new Ext.PagingToolbar({
displayInfo : true,
displayMsg : '{0} - {1} of {2}',
emptyMsg : 'No Data',
pageSize : 50,
store : store
});
// Create the Grid Panel
var grid = new xg.GridPanel({
bbar : pagingBar,
columns : columns,
height : 500,
iconCls : 'icon-grid',
loadMask : {msg: 'Loading data.', enabled: true},
plugins : [expander, rowEditor],
renderTo : 'dbGrid',
sm : new Ext.grid.RowSelectionModel({singleSelect:true}),
store : store,
stripeRows : true,
tbar : [
'->', {
text : 'Upload Accounts',
tooltip : 'Upload Accounts',
iconCls : 'icon-add',
handler : uploadFormWindow
},
'->', {
handler : reload,
iconCls : 'icon-tableRefresh',
text : 'Show All',
tooltip : 'Show all records.'
},
],
title : 'Accounts',
viewConfig : {
forceFit : true
}
});
// Create the Uplaod Form
var uploadItems = new Ext.FormPanel({
autoHeight : true,
bodyStyle : 'padding: 10px;',
buttons: [{
text : 'Save',
handler : function() {
if (uploadItems.getForm().isValid()) {
uploadCreateWindow.hide();
uploadItems.getForm().submit({
waitMsg : 'Uploading your accounts',
failure : function(uploadItems, data) {
msg('Failure', data.result.message);
},
success : function(uploadItems, data) {
msg('Success', data.result.message);
store.reload();
},
url : '/accounts/upload'
});
}
}
},{
text : 'Reset',
handler : function() {
uploadItems.getForm().reset();
}
},{
text : 'Close',
handler : function() {
uploadCreateWindow.hide();
}
}],
defaults : {
anchor : '90%',
allowBlank : false,
msgTarget : 'side'
},
fileUpload : true,
frame : true,
items : [{
height : 28,
xtype : 'fileuploadfield',
id : 'uploadFile',
emptyText : 'Select a file',
fieldLabel : 'Select File',
name : 'uploadFile',
buttonCfg : {
text : '',
iconCls : 'icon-add'
}
},
new Ext.form.ComboBox({
allowBlank : false,
displayField : 'bankName',
emptyText : 'Bank Name',
fieldLabel : 'Bank',
forceSelection : true,
mode : 'local',
store : new Ext.data.SimpleStore({
fields : ['bankValue', 'bankName'], data: [['Natwest','Natwest']]
}),
triggerAction : 'all',
valueField : 'bankValue'
}),
],
labelWidth : 75,
width : 400
});
// Create the Panel to hold the Upload Form
var uploadCreateWindow = new Ext.Window({
autoHeight : true,
closable : true,
closeAction : 'hide',
height : 150,
iconCls : 'icon-grid',
items : uploadItems,
layout : 'fit',
title : 'Upload Accounts',
width : 450
});
// Create an event handler for the company selection
grid.on('cellclick', function(grid, row, col, e) {
var tgt = e.getTarget();
var rec = grid.getStore().getAt(row);
var field = grid.getColumnModel().getDataIndex(col);
if (field == 'vat') {
if (tgt.tagName.toLowerCase() == 'a') {
grid.getStore().load({params: { 'vatID': rec.get('vat'), 'limit': 50, 'start': 0 } } );
store.baseParams.vatID = rec.get('vat');
e.stopEvent();
}
}
});
});
Ok so when I edit my row in the grid with Roweditor - the combobox immediately shows the valuefield - which is simply an ID and not the display field the user selected from
I have done quite a bit of searching - either the topics are very general or there are no signs of guidance
I was also looking to see if the ExtJS support a kind of callback - ie the JSON is submitted in the Success message there is JSON to overwrite the fields with fresh data. I though I read something that this was possible but see no help on this anywhere
The last thing to try I suppose would be to capture the update listener of the row editor and force the correct text into the row instead of the valuefield ID number.
Open to suggestions please
Included the code for this
Ext.BLANK_IMAGE_URL = 'http://extjs.cachefly.net/ext-3.0.0/resources/images/default/s.gif';
Ext.onReady(function()
{
// Instantiate the quick tips
Ext.QuickTips.init();
var xg = Ext.grid;
// Use RowEditor for editing
var rowEditor = new Ext.ux.grid.RowEditor({
errorSummary : false,
saveText : 'Update'
});
var msg = function(title, msg) {
Ext.Msg.show({
buttons : Ext.Msg.OK,
icon : Ext.Msg.INFO,
msg : msg,
minWidth : 200,
modal : true,
msg : msg,
title : title
});
};
// Display or bring forth the form
function uploadFormWindow()
{
if (!uploadCreateWindow.isVisible()) {
uploadCreateWindow.show();
} else {
uploadCreateWindow.toFront();
}
}
// Method to display negative numbers in a different colour
function renderNegativeAmount(val)
{
if (val < 0) {
var className = 'style="color: red"';
} else {
var className = 'style="font-weight: bold"';
}
return '<span ' + className + '>' + val + '</span>';
}
function renderVatLink(val, p, record)
{
return('<a id="myClickableField" href="/restaccounts/data/vatID/' + record.data.id + '" title="VAT Records">' + val + '</a>');
}
function reload()
{
store.baseParams.vatID = null;
store.reload({
params: {
start:0, limit:50, sort:'date', dir:'DESC'
}
});
}
// The DataWriter component.
var writer = new Ext.data.JsonWriter({
encode : false,
writeAllFields : true
});
// Create the data store
var store = new Ext.data.JsonStore({
fields : [
{ name: 'id', type: 'int' },
{ name: 'date', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'reference', type: 'string' },
{ name: 'invoice', type: 'string' },
{ name: 'payment', type: 'string' },
{ name: 'vat', type: 'int' }
],
idProperty : 'id',
messageProperty : 'data',
remoteSort : true,
restful : true,
root : 'data',
successProperty : 'success',
totalProperty : 'totalCount',
url : '/restaccounts',
writer : writer
});
// Create the Reference data store
var storeReference = new Ext.data.JsonStore({
fields : [
{ name : 'id', type: 'int' },
{ name : 'reference', type: 'string' }
],
root : 'data',
url : '/accounts/reference'
});
store.setDefaultSort('date', 'DESC');
store.load({params:{start:0, limit:50, sort:'date', dir:'DESC'}});
// Row expander
var expander = new Ext.grid.RowExpander({
expandOnDblClick : false,
tpl : new Ext.Template(
'<p style="margin-left: 50px; width: 99%; padding: 10px;"><b>Notes:</b> {description}</p>'
)
});
// create the column model
var columns = [
new xg.RowNumberer(),
expander,
{ header: 'Date', sortable: true, dataIndex: 'date' },
{ header: 'Reference', sortable: true, dataIndex: 'reference',
editor : {
allowBlank : false,
displayField : 'reference',
emptyText : 'Select Reference',
fieldLabel : 'Reference',
forceSelection : true,
lazyRender : true,
mode : 'remote',
name : 'reference',
store : storeReference,
typeAhead : true,
triggerAction : 'all',
valueField : 'id',
xtype : 'combo'
}
},
{ header: 'Invoice', sortable: true, dataIndex: 'invoice',
editor: {
xtype : 'textfield'
}
},
{ header: 'Payment', sortable: true, dataIndex: 'payment', renderer: renderNegativeAmount },
{ header: 'VAT', sortable: true, dataIndex: 'vat', renderer: renderVatLink,
editor : {
maxValue : 100,
minValue : 1,
xtype : 'numberfield'
}
}
];
// Create the pager
var pagingBar = new Ext.PagingToolbar({
displayInfo : true,
displayMsg : '{0} - {1} of {2}',
emptyMsg : 'No Data',
pageSize : 50,
store : store
});
// Create the Grid Panel
var grid = new xg.GridPanel({
bbar : pagingBar,
columns : columns,
height : 500,
iconCls : 'icon-grid',
loadMask : {msg: 'Loading data.', enabled: true},
plugins : [expander, rowEditor],
renderTo : 'dbGrid',
sm : new Ext.grid.RowSelectionModel({singleSelect:true}),
store : store,
stripeRows : true,
tbar : [
'->', {
text : 'Upload Accounts',
tooltip : 'Upload Accounts',
iconCls : 'icon-add',
handler : uploadFormWindow
},
'->', {
handler : reload,
iconCls : 'icon-tableRefresh',
text : 'Show All',
tooltip : 'Show all records.'
},
],
title : 'Accounts',
viewConfig : {
forceFit : true
}
});
// Create the Uplaod Form
var uploadItems = new Ext.FormPanel({
autoHeight : true,
bodyStyle : 'padding: 10px;',
buttons: [{
text : 'Save',
handler : function() {
if (uploadItems.getForm().isValid()) {
uploadCreateWindow.hide();
uploadItems.getForm().submit({
waitMsg : 'Uploading your accounts',
failure : function(uploadItems, data) {
msg('Failure', data.result.message);
},
success : function(uploadItems, data) {
msg('Success', data.result.message);
store.reload();
},
url : '/accounts/upload'
});
}
}
},{
text : 'Reset',
handler : function() {
uploadItems.getForm().reset();
}
},{
text : 'Close',
handler : function() {
uploadCreateWindow.hide();
}
}],
defaults : {
anchor : '90%',
allowBlank : false,
msgTarget : 'side'
},
fileUpload : true,
frame : true,
items : [{
height : 28,
xtype : 'fileuploadfield',
id : 'uploadFile',
emptyText : 'Select a file',
fieldLabel : 'Select File',
name : 'uploadFile',
buttonCfg : {
text : '',
iconCls : 'icon-add'
}
},
new Ext.form.ComboBox({
allowBlank : false,
displayField : 'bankName',
emptyText : 'Bank Name',
fieldLabel : 'Bank',
forceSelection : true,
mode : 'local',
store : new Ext.data.SimpleStore({
fields : ['bankValue', 'bankName'], data: [['Natwest','Natwest']]
}),
triggerAction : 'all',
valueField : 'bankValue'
}),
],
labelWidth : 75,
width : 400
});
// Create the Panel to hold the Upload Form
var uploadCreateWindow = new Ext.Window({
autoHeight : true,
closable : true,
closeAction : 'hide',
height : 150,
iconCls : 'icon-grid',
items : uploadItems,
layout : 'fit',
title : 'Upload Accounts',
width : 450
});
// Create an event handler for the company selection
grid.on('cellclick', function(grid, row, col, e) {
var tgt = e.getTarget();
var rec = grid.getStore().getAt(row);
var field = grid.getColumnModel().getDataIndex(col);
if (field == 'vat') {
if (tgt.tagName.toLowerCase() == 'a') {
grid.getStore().load({params: { 'vatID': rec.get('vat'), 'limit': 50, 'start': 0 } } );
store.baseParams.vatID = rec.get('vat');
e.stopEvent();
}
}
});
});