PDA

View Full Version : RowEditor CRUD issue: Overwriting unchanged cells with Blank or Bad Data



Tumac
13 Dec 2010, 1:31 PM
I have implemented Roweditor for a grid and have my CRUD operations working properly except for the fact that RowEditor will overwrite an unchanged cell with either the Raw display value or null if the cell is not changed.

Example:

In my grid I have drop downs with a different stored value and display value. If use the drop down to change the value, Roweditor sends the "key" value as specified. If I do not change the value in the dropdown, then the Roweditor sends the display value which then updates the cell in the DB s null since it is an incompatible cell type.

GRID


Ext.ns('STScls.mtce.grids');

var price_edit = new Ext.form.TextField();
var cost_edit = new Ext.form.TextField();
var priceUM_edit = new Ext.form.ComboBox({
typeAhead: true
,triggerAction: 'all'
,name: 'PriceUM'
,id: 'priceumEdit'
,displayField:'uomDesc'
,editable:false
,valueField: 'uomID'
,hiddenName: 'uomID'
,store: {
xtype: 'jsonstore'
,url: '?c=lookup&m=uom'
,autoLoad: false
,fields: ['uomID','uomDesc']
}
,listClass: 'x-combo-list-small'
});
var costUM_edit = new Ext.form.ComboBox({
typeAhead: true
,triggerAction: 'all'
,name: 'CostUM'
,id: 'costumEdit'
,displayField:'uomDesc'
,editable:false
,valueField: 'uomID'
,hiddenName: 'uomID'
,store: {
xtype: 'jsonstore'
,url: '?c=lookup&m=uom'
,autoLoad: false
,fields: ['uomID','uomDesc']
}
,listClass: 'x-combo-list-small'
});
var qtyUM_edit = new Ext.form.ComboBox({
typeAhead: true
,triggerAction: 'all'
,name: 'QtyUM'
,id: 'qtyumEdit'
,displayField:'uomDesc'
,editable:false
,valueField: 'uomID'
,hiddenName: 'uomID'
,store: {
xtype: 'jsonstore'
,url: '?c=lookup&m=uom'
,autoLoad: false
,fields: ['uomID','uomDesc']
}
,listClass: 'x-combo-list-small'
});

var mill_edit = new Ext.form.ComboBox({
typeAhead: true
,triggerAction: 'all'
,name: 'millID'
,id: 'millEdit'
,displayField:'millShort'
,editable:false
,valueField: 'millID'
,hiddenName: 'millID'
,store: {
xtype: 'jsonstore'
,url: '?c=lookup&m=mills'
,autoLoad: false
,fields: ['millID','millShort','millName']
}
,listClass: 'x-combo-list-small'
});





function money(value, metadata, record) {
return ['$ ',value].join('');
}

STScls.mtce.grids.MillCosting = Ext.extend(Ext.grid.GridPanel, {
url : '?c=maintenance&m=listForMaster'
,itemId: 'millCostGrid'
//,enableDragDrop: true
//,ddGroup : 'deliveryDD'
,viewConfig : {forceFit:true }
,stripeRows : true
,columns :
[
{header: "Mill", dataIndex: 'millName', hidden:true}
,{header: "Mill", dataIndex: 'millShort',width:75,editor: mill_edit}
,{header: "Item", dataIndex: 'skuID', width:60,hidden:true}
,{header: "Description", dataIndex: 'cusDescription',width:300,readOnly:true}
,{header: "Mill Cost", dataIndex: 'cost', width:60,renderer: Ext.util.Format.usMoney ,editor: cost_edit}
,{header: "Cost UM", dataIndex: 'cost_uom', width:60,editor: costUM_edit}
,{header: "Sell Price", dataIndex: 'price', width:60,editor: price_edit,renderer:money}
,{header: "Sell UM", dataIndex: 'price_uom', width:60,editor: priceUM_edit}
,{header: "Purch UM", dataIndex: 'pur_uom', width:60, editor:qtyUM_edit}
]

,collapsible: false
,animCollapse: false
,sm: new Ext.grid.RowSelectionModel({multiSelect: true})

,clicksToEdit: 2

,initComponent : function() {
this.store = this.buildStore();
STScls.mtce.grids.MillCosting.superclass.initComponent.call(this);
}

,buildStore : function() {
return {
xtype : 'jsonstore'
,url : this.url
,autoLoad : false
,writeAllFields: true
,sortInfo : {field: 'millID',dir: 'ASC' }
,totalProperty: 'totalRows'
,root: 'data'
,fields : [
{name: 'millName'}
,{name: 'millID'}
,{name: 'millShort'}
,{name: 'skuID'}
,{name: 'tallyStatus'}
,{name: 'cusDescription'}
,{name: 'cost',type:'float'}
,{name: 'cost_uom'}
,{name: 'defCostUM'}
,{name: 'defQtyUM'}
,{name: 'pur_uom'}
,{name: 'price_uom'}
,{name: 'defPriceUM'}
,{name: 'price',type:'float'}
,{name: 'seq'}
,{name: 'costID'}

]
};
}

,add : function(rec) {
var store = this.store;
var sortInfo = store.sortInfo;

if (Ext.isArray(rec)) {
Ext.each(rec, function(rObj, ind) {
if (! (rObj instanceof Ext.data.Record)) {
rec[ind] = new this.store.recordType(rObj);
}
});
}
else if (Ext.isObject(rec) && ! (rec instanceof Ext.data.Record)) {
rec = new this.store.recordType(rec);
}

store.add(rec);
store.sort(sortInfo.field, sortInfo.direction);
},
loadData : function(d) {
return this.store.loadData(d);
},
load : function(o) {
return this.store.load(o);
},
removeAll : function() {
return this.store.removeAll();
},

remove : function(r) {
return this.store.remove(r);
},
getSelected : function() {
return this.selModel.getSelections();
}

});

Ext.reg('millcostinggrid', STScls.mtce.grids.MillCosting);

UPDATE ROUTINE


,onUpdateRecord : function(grid,data,record) {

Ext.Ajax.request({
url : '?c=maintenance&m=updatePricing'
,method : 'POST'
,params : {
costID : record.data.costID
,millID : record.data.millShort
,skuID : record.data.skuID
,defQtyUM : record.data.pur_uom
,defCostUM : record.data.cost_uom
,defPriceUM : record.data.price_uom
,cost : record.data.cost
,price : record.data.price

}
,success : function(response,options) {
var obj = Ext.decode(response.responseText);
if (obj.success) {
var grid=Ext.getCmp("millCostGrid");
grid.store.reload();
} else {
Ext.MessageBox.alert("Error",obj.msg);
}
}
});
}
thanks is advance