PDA

View Full Version : Grid sorting on add/change record



KJedi
25 Apr 2008, 2:25 AM
When I add record to the grid, user should fill in the data he needs. And after that record should be placed where it should be (records are sorted by date).
records are not sorted automatically, so I do th following:
1)add button listenter:

'click':{
fn:function()
{
if (this.store.getCount() >= 10)
{
Ext.Msg.alert('Error','You can\'t add more than 10 projects to the hotlist!');
}
else
{
var ids = this.store.collect('HotlistID', false, true);
var newID = ids.sort(Nut.routines.cmpNumbers)[ids.length - 1] + 1;
var s = new Nut.App.Interface.HL.HotlistRecord({
HotlistID: newID,
Type: this.type,
ProjectID: 0,
Reason:'',
Notes:'',
CreatedBy:Nut.App.User.UserID,
CreatedDate:new Date(),
LastUpdatedBy:Nut.App.User.UserID,
LastUpdatedDate:new Date()
}, newID);
this.stopEditing();
this.store.add(s);
this.startEditing(this.store.getCount()-1, 0);
}
},
scope:this
}
2)Subscribe to update event:

initComponent:function()
{
...
this.store.on('update', this.handleSave, this);
...
},
3)catch update event:

if (operation == Ext.data.Record.COMMIT)
{
Ext.Msg.alert('Saving', 'Mock function, saving (on the server) will be done here');
}
else
{
if (operation == Ext.data.Record.UPDATE)
{
//update some helper fields
record.set('LastUpdatedBy', Nut.App.UserID);
record.set('LastModifiedBy', new Date());
//get current sort state
var state = store.getSortState();
//sort
store.sort(state.field, state.direction);
}
}
That's not working :(
When I debug in firebug, it shows me that it executes only the last line:

store.sort(state.field, state.direction);
as skips previous 3:


//update some helper fields
record.set('LastUpdatedBy', Nut.App.UserID);
record.set('LastModifiedBy', new Date());
//get current sort state
var state = store.getSortState();

Why??? What am I doing wrong?

Working application is here: http://nutec.takeforce.net/Nut_UI.htm
Hit "login", then "OK" in the message and in the interface appeared switch to the Priority rankings tab (last tab).
Click "Add project" button and set any date. It should be sorted by date and it should update "LastModifiedBy" and "LastModifiedDate" fields ofthe record when you edit any existing one.

Script is located in the lib/custom/JS/Hotlists/GenericHotlist.js

Thanks beforehand!

KJedi
25 Apr 2008, 2:29 AM
Sorry, I solved it. I was listening to the wrong operation, I should write

if (operation == Ext.data.Record.EDIT)
and I wrote

if (operation == Ext.data.Record.UPDATE)
And there is no UPDATE operation in the Store class