View Full Version : How to cancel grid sorting?
jsakalos
11 May 2007, 4:02 AM
Currently, if you click a column header the grid gets sorted by this column. If you click again the sort order is reversed.
Is there any possibility to NOT-to-sort. In another words, how do I cancel sort (after click of col header) without clicking another column to revert to original sort order?
Note: I have remoteSort: true.
BernardChhun
11 May 2007, 4:42 AM
I tried different things with the grid's dataSource and I can't seem to block it at will either. :-? I'm interested in how this could be done :)
jay@moduscreate.com
11 May 2007, 8:57 AM
disable sorting then.
jsakalos
11 May 2007, 9:32 AM
You haven't got my point. I need:
ASC
DESC
NONE
FlexIDX
14 May 2007, 2:32 PM
I need this feature as well, I have several fields/columns and want some to be sortable and some to not be sortable I would really like to be able to turn it off or on, on a per column basis.
Chris
jsakalos
14 May 2007, 2:41 PM
Yeah, reading your answer it comes to my mind that once I implemented in PHP sorting by more than one column. It worked like this:
Click one column = toggle asc/desc
Shift+Click the same column = no sort/sort off
Shift+Click another column = add that column to order by field list
Shift+Click that another column again = toggle that another column asc/desc
Simple click a column after sorted by multiple another columns = turn off sorting by others and do point 1.
It would be nice to have same feature in Ext, although, now it's not make/break point in the app I'm developing.
Troy Wolf
25 Oct 2007, 8:30 AM
It is interesting to me that this thread has not gone anywhere. I have a very similar issue with column sorting, but as it pertains to v2.0, I'll post a new thread in the 2.0 Help forum.
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
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 ;-)
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"
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 :-)
pwnfactory
15 Sep 2009, 10:15 AM
You haven't got my point. I need:
ASC
DESC
NONE
Did you find a solution for this? We're looking for the same thing. Thanks
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.