PDA

View Full Version : Check Column and HttpProxy



omermx
10 Dec 2009, 3:20 AM
Hi, I have a grid component with the check column plugin. I have a HttpProxy associated with the grids store so that when there is a change the update url is called. I also have autoSave:disabled on the store so any changes are submitted in one go.

My problem is that there doesn't seem to be a way to distinguish between whether the checkbox in a particular row is checked or not - i.e. I could check a checkbox and then uncheck it and it is still registered as an update when I call store.save();

Is there some other way to capture the values of check boxes in a checkcolumn?

Thanks.

Condor
10 Dec 2009, 3:40 AM
You could reject all records that were changed to their original values, e.g.

Ext.each([].concat(store.getModifiedRecords()), function(record){
var reject = true;
Ext.iterate(record.modified, function(name, value){
var encode = Ext.isPrimitive(value) ? String : Ext.encode;
if(encode(record.data[name]) != encode(value)) {
return (reject = false);
}
});
if(reject){
record.reject();
}
});

omermx
10 Dec 2009, 3:44 AM
Hi Condor, thanks for the quick response - where/when would I specify the settings you suggest? Can I put the code anywhere after the store is declared?

Condor
10 Dec 2009, 3:50 AM
You would call this before calling store.save().

omermx
10 Dec 2009, 4:36 AM
That doesn't seem to work, the id's all of rows changed (checked or not) are still passed as parameters in the update request. Here is how my store is setup, and where I call store.save():




var store = new Ext.data.Store({
id: 'user',
autoSave:false,
proxy: proxy,
reader: reader,
writer: writer,
listeners: {
write : function(store, action, result, response, rs) {
console.log(response.success, response.message);
}
}
});

.
.
.

Ext.each([].concat(store.getModifiedRecords()), function(record){
var reject = true;
Ext.iterate(record.modified, function(name, value){
var encode = Ext.isPrimitive(value) ? String : Ext.encode;
if(encode(record.data[name]) != encode(value)) {
return (reject = false);
}
});
if(reject){
record.reject();
}
});


store.save();




Any ideas where I might be going wrong?

Condor
10 Dec 2009, 5:13 AM
I haven't debugged it.

The code is supposed to reject ('unmodify') all records that only have changed fields of which the value is identical to the original value.

omermx
10 Dec 2009, 6:17 AM
Ok, I'm not sure what's going on in the logic of the function, but I put in console.log() inside the if statement and it is never called, hence all the records still get passed as updated:



if(reject){
console.log('record rejected');
record.reject();
}

Condor
10 Dec 2009, 6:28 AM
Try these log statements:

Ext.each([].concat(store.getModifiedRecords()), function(record){
var reject = true;
Ext.iterate(record.modified, function(name, value){
var encode = Ext.isPrimitive(value) ? String : Ext.encode;
if(encode(record.data[name]) != encode(value)) {
console.log('modified', record.data, record.modified);
return (reject = false);
}
});
if(reject){
console.log('unmodified', record.data, record.modified);
record.reject();
}
});

omermx
10 Dec 2009, 12:44 PM
Hi, so I put in the lines you recomended and got some strage results. The code for 'unmodified' never seems to get called, however with:



if(encode(record.data[name]) != encode(value)) {
console.log('modified', record.data, record.modified);
return (reject = false);
}


If I have a checked box I get:



modified Object pat_id=pat_0 Object


If I check a box and then uncheck it (i.e. it's back to the original value), I get:



modified Object pat_id=pat_1 Object checked=true


It's almost as thought the check column is inverted??

Any ideas?

Cheers!

Condor
11 Dec 2009, 1:47 AM
You have to click on the data and modified objects to see what they actually hold (or change the console.log to console.dir).

omermx
11 Dec 2009, 2:37 AM
Hi, I should have been paying attention to what was actually being passed to the server:




data[{"no_print":true,"pat_id":"pat_19234"},{"no_print":true,"pat_id":"pat_56348"}]

pat_id["pat_19234","pat_56348"]



For each element in 'data' it shows which rows were updated and the value of the checkbox i.e. true.

Thanks for your help.