PDA

View Full Version : Changing store from an action



dobberph
7 Nov 2012, 9:11 AM
Hi all,

I think I have a simple problem, but I'm to silly to solve it ^^.
I have an actioncolumn in an gridpanel that is provided by an MVC-structure with a store.

The definition of the column is:


{
xtype: 'actioncolumn',
text: 'prüfen',
width: 45,
align: 'center',
items: [
{
handler: function(view, rowIndex, colIndex, item, e, record, row) {

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //beacuse January would be 0
var yyyy = today.getFullYear();
if (dd<10) {
dd = '0'+dd;
}
today = yyyy + '-' + mm + '-' + dd;
view.getStore().getById(record.data.id).data.referenzecho_lastchange = today;
view.getStore().fireEvent('datachanged',{});
view.getStore().commitChanges();
view.getStore().sync();
view.refresh();
},
icon: 'extjs/examples/desktop/images/gears.png',
}
]
},


I simply want to change a field of the actual record of the store to the current date. But I cant get the store save my changes. What's my problem here?`I dont understand it.

Thank a lot,
Tobias

Tim Toady
7 Nov 2012, 9:20 AM
You shouldn't need to refresh your view or fire datachanged manually. Don't modify record.data manually. Use the record.set method.

dobberph
7 Nov 2012, 9:34 AM
Thanks. It works now with this code:



record.beginEdit();
record.set('referenzecho_lastchange', today);
record.endEdit();

Tim Toady
7 Nov 2012, 9:43 AM
If you are only setting one field, I don't see a purpose in using beginEdit and endEdit.