PDA

View Full Version : Direct Grid new row apears selected



TopKatz
12 Nov 2010, 8:36 AM
I have a Grid that uses a store with a direct proxy and writer.



Ihc.app.DirectProxy = new Ext.data.HttpProxy({
api:{
read:Ihc.app.DirectRequestURL+'/readOrderItems',
create:Ihc.app.DirectRequestURL+'/newOrderItem',
update:Ihc.app.DirectRequestURL+'/updateOrderItem',
destroy:Ihc.app.DirectRequestURL+'/deleteOrderItem'
}
});

Ihc.app.DirectWriter = new Ext.data.JsonWriter({
encode:true,
writeAllFields:true,
listful:true
});

Ihc.app.reader = new Ext.data.JsonReader({
totalProperty: 'total',
successProperty: 'success',
idProperty: 'orderItemID',
root: 'data',
messageProperty: 'message'
}, [
{name: 'orderItemID'},
{name: 'item'},
{name: 'itemID'},
{name: 'size'},
{name: 'quantity'},
{name: 'categoryID'},
{name: 'comment'},
{name:'orderID'},
{name:'unlistedItem'}
]);

Ihc.app.dsOrder = new Ext.data.Store({
proxy:Ihc.app.DirectProxy,
writer:Ihc.app.DirectWriter,
autoSave:false,
reader:Ihc.app.reader,
baseParams:{orderID:null},
listeners:{
exception : function(m){
console.log(m)
//Ihc.app.dsOrder.baseParams.orderID = null;
Ihc.app.dsOrder.removeAll();
Ihc.app.dsOrder.commitChanges();
},
write:function(s,a,o){
console.log(s,a,o)
if(a == "create"){
if(o[0].orderID){
Ihc.app.dsOrder.baseParams.orderID = o[0].orderID;
Ihc.app.OrderDetail.orderID = o[0].orderID;
console.log(o[0].orderItemID)
idx = Ihc.app.dsOrder.findExact('orderItemID',o[0].orderItemID);
rec = Ihc.app.dsOrder.getAt(idx);
rec._phid = o[0].orderItemID;
Ihc.app.dsOrder.reMap(rec);
Ihc.app.dsOrder.commitChanges();
console.log(s,a,o,rec)
}
}
},
remove:function(s,r){
// console.log(s,r)
}
}
});


After I add a record :



var rec = Ihc.app.dsItems.getAt(i);
rec.data.quantity = 1;
var newRec = new Ihc.app.dsOrder.recordType(rec.data);
Ihc.app.dsOrder.insert(0,newRec);
Ihc.app.dsOrder.save();



My json going out looks like this:



data [{"itemID":"26160","item":"CHICKEN FEET","categoryID":"7809","quantity":1}]
orderID 5


and comming back like so:



{"success":true,"orderID":5,"message":"Record added to the Order!","data":[{"orderItemID":"44","orderID":"5","itemID":"26160","size":"","quantity":"1","comment":"","unlistedItem":"","categoryID":"7809","item":"CHICKEN FEET"}]}


The grid is a single select, and if I select this new record it appears as though its always selected afterward. So if I click another row(one that was loaded, not added) it never removes selection from the added row. I thought maybe this was an issue with the _phID however that all looks good. I added a remap call also. I can retrive the new record using the idProperty, however Im seeing this odd behavior .

Anyone have any ideas for me?

TopKatz
12 Nov 2010, 10:16 AM
I have tracked this down to how Im adding the record. When I insert it at the top of the grid it is messing up the index order. Its not just effecting the first record but also the last. If I cahnge the insert to go in the bottem of the grid everything works. Not sure how to enable the entry at the top, but for now I will insert at the end.

So I was inserting at 0, now I get the count and insert there and all is well. To use it like this Im now focusing the grid at the end.

This will work but is not ideal.