PDA

View Full Version : Not getting the record after editing in afteredit using RowEditor



dhiraj17
12 Apr 2012, 3:25 AM
I am getting the record in the afteredit event of the RowEditor. Here is my code:



<script type="text/javascript">
Ext.Loader.setConfig({ enabled: true });
Ext.require([
'Ext.grid.*',
'Ext.data.*',
'Ext.util.*',
'Ext.toolbar.Paging',
'Ext.ModelManager',
'Ext.tip.QuickTipManager'
]);


Ext.onReady(function () {
var model = Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: ['EmpID', 'FirstName', 'LastName', 'Email'],
idProperty: 'EmpID'
});
var store = Ext.create('Ext.data.Store', {
storeId: 'empStore',
model: 'Employee',
// autoLoad: true,
pageSize: 5,
proxy: {
type: 'ajax',
url: 'AddOffice.aspx/GetEmployees',
headers: {
'Content-Type': 'application/json'
},
reader: {
type: 'json',
root: 'd.Records',
totalProperty: 'd.TotalRecords',
successProperty: 'success'
}
}
});
store.load({ params: {
start: 0,
limit: 5
}
});
var editor = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1
});
editor.on({
scope: this,
afteredit: function (roweditor, changes, record, rowIndex) {
alert(record);
}
});
var grid = Ext.create('Ext.grid.Panel', {
title: 'Employees',
store: store,
id: 'EList',
height: 200,
width: 500,
loadMask: true,
plugins: [editor],
renderTo: Ext.getBody(),
selType: 'rowmodel',
columns: [
{ header: 'Employee ID', dataIndex: 'EmpID', flex: 1, hidden: true },
{ header: 'First Name', dataIndex: 'FirstName', flex: 1, editor: { allowblank: false} },
{ header: 'Last Name', dataIndex: 'LastName', flex: 1, editor: { allowblank: false} },
{ header: 'Email', dataIndex: 'Email', flex: 1, editor: { allowblank: false, vtype: 'email'} }
],
bbar: Ext.create('Ext.PagingToolbar', {
store: store,
pageSize: 5,
displayInfo: true
})
});
// grid.renderTo(Ext.getBody);
});
</script>

scottmartin
12 Apr 2012, 2:41 PM
Does your server return the record after editing? Can you see the updated record in your response tab using FireBug?

Regards,
Scott.

vietits
12 Apr 2012, 3:32 PM
editor.on({
scope: this,
afteredit: function (roweditor, changes, record, rowIndex) {
alert(record);
}
});

As I known with Ext 4.x, Ext.grid.plugin.RowEditing fires 'afteredit' event which is in fact 'edit' event with the following arguments


edit( Ext.grid.plugin.Editing editor, Object e, Object eOpts )

So, let have a try by modifying your code as below


editor.on({
scope: this,
edit: function (roweditor, event) {
alert(event.record);
}
});

dhiraj17
15 Apr 2012, 9:37 PM
Hi vietits,
This doesnot work either. I still the get the record as undefined


editor.on({
scope: this,
edit: function(roweditor, event){
alert(event.record);
}
});


The following code works for me:


editor.on({
scope: this,
edit: function(roweditor, event){
alert(roweditor.record);
}
});

vietits
15 Apr 2012, 11:28 PM
With Ext 4.0, you should use


editor.on({
scope: this,
edit: function(event){
alert(event.record);
}
});

But with Ext 4.1, you should use


editor.on({
scope: this,
edit: function(roweditor, event){
alert(event.record);
}
});

I guess you are using Ext 4.0.x.

dhiraj17
16 Apr 2012, 1:09 AM
Hi Vietits,

Yes you are right. Thanks for the answer.