I've just had to implement this in a v1.1 app, here's how i did it:
firstly... add an extra named object thingy to your records definition... something like 'originalOrder' has been added below:
NB XmlStringReader is a custom class that i extended from Ext.data.XmlReader
PHP Code:
var myRecord= Ext.data.Record.create([
{name: 'somefield1', type: 'string'},
{name: 'somefield2', type: 'int'},
{name: 'originalOrder', type: 'int'} //add extra field here...
]);
var gridXMLStringReader = new Ext.data.XmlStringReader({
record: 'theXMLTagName'
}, myRecord);
var myGridDataStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: myURL}),
reader: gridXMLStringReader
});
var myGrid = new Ext.grid.EditorGrid('myGridsDiv', {
ds: myGridDataStore ,
cm: myGridColModel,
selModel: new Ext.grid.RowSelectionModel(),
rememberSortOrder:true, //add this to all the grids you want to enable this feature
etc., etc.,
});
ok now, override handleHeaderClick in Ext.grid.GridView:
we are adding the if statement:
if (this.ds.getSortState() == null && this.grid.rememberSortOrder) {this.RememberSortOrder();}
and the function RememberSortOrder()
NB this.ds.getSortState() == null when the store is being sorted for the first time...
ie the first time you click a column's header...
RememberSortOrder() simply populates the originalOrder field of each record sequentially creating an index ;-)
PHP Code:
Ext.override(Ext.grid.GridView, {
/* This overrides the default header click and adds a call to remember the previous sort order */
handleHeaderClick : function(g, index) {
if (this.headersDisabled) {
return;
}
var dm = g.dataSource, cm = g.colModel;
if (!cm.isSortable(index)) {
return;
}
g.stopEditing();
if (this.ds.getSortState() == null && this.grid.rememberSortOrder) { this.RememberSortOrder();} //if the header hasn't been clicked before
dm.sort(cm.getDataIndex(index));
},
RememberSortOrder : function() {
var order = 1;
this.ds.each(function(record) {
record.data.originalOrder = order;
order++;
});
}
});
so far easy... and so is the rest ;-) ...read on
Create two functions: "UnSort" & "SaveSort"
PHP Code:
function UnSort() {
myGridDataStore.each(function(rec) {
if (!rec.data.originalOrder) {rec.data.originalOrder = 0;}
});
myGridDataStore.sort("originalOrder", "ASC");
var count = 0;
myGridDataStore.each(function(rec) {
if (rec.data.originalOrder == 0) {
Ext.fly(myGrid.getView().getRow(count)).highlight("ff9999", {attr:'background-color', duration:3});
count++;
}
});
}
function SaveSort() {
var order = 1;
myGridDataStore.each(function(rec) {
rec.data.originalOrder = order;
order++;
});
}
SaveSort basically re-indexs the grid, in case you want to change the order and make a save point...
UnSort basically reverts the rows back to the original or saved order... and any new rows added will appear at the top and will be highlighted in red.
Obviously this way-of-doing-it won't suit everyone, but it was enough for me, so hope it helps someone else too.
long live EXT ;-)
NB this hasn't been exhaustively tested yet and it may not be the best method to do this but i found it easy to understand and implement so i guess it will be the same for other newbie's :-)