PDA

View Full Version : [CLOSED] GroupingStore sort does not seem to work well



yleguern
17 Sep 2008, 7:01 AM
Hello,

I think there is a bug in the GroupingStore sort method.
I want my grid to be sorted first on the "grouped by" column, but when those "grouped by" columns have the same sort index, the group by does not work anymore.

At the beginning, everything is fine (the store is not sorted)

http://img221.imageshack.us/img221/2362/screen1xh1.gif

But when I sort the store (click on the "Player" header column) :

http://img222.imageshack.us/img222/1848/screen2ga3.gif

Here is my code :


package test.client;
import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.store.*;
import com.extjs.gxt.ui.client.widget.grid.*;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
public class App implements EntryPoint
{
public void onModuleLoad()
{
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
configs.add(new ColumnConfig("name", "Player", 200));
configs.add(new ColumnConfig("ctry", "Country", 60));
configs.add(new ColumnConfig("id", "ID", 30));
ColumnModel cm = new ColumnModel(configs);
GroupingStore<MyModel> store = new GroupingStore<MyModel>();
store.add(new MyModel(1, "Nadal Rafael" , "ESP", 2));
store.add(new MyModel(2, "Federer Roger" , "SUI", 2));
store.add(new MyModel(1, "Djokovic Novak", "SRB", 2));
store.add(new MyModel(3, "Murray Andy" , "GBR", 1));
store.add(new MyModel(3, "David Ferrer" , "ESP", 1));
store.groupBy("id");
store.setStoreSorter(new StoreSorter<MyModel>(){
public int compare(Store<MyModel> in_store, MyModel m1, MyModel m2, String property){
if ("id".equals(property)){
// Sort grouped column
return m1.sortIndex - m2.sortIndex;
}
// Sort other columns
String v1 = m1.get(property);
String v2 = m2.get(property);
return v1.compareToIgnoreCase(v2);
}
});
GroupingView view = new GroupingView();
view.setGroupRenderer(new GridGroupRenderer(){
public String render(GroupColumnData data)
{
return "Group " + data.models.get(0).get("id");
}
});
Grid<MyModel> grid = new Grid<MyModel>(store, cm);
grid.setView(view);
grid.setBorders(true);
grid.setSize(300, 300);
RootPanel.get().add(grid);
}
public static class MyModel extends BaseModel {
int sortIndex;
public MyModel(int groupId, String name, String country, int groupSortIndex) {
set("id", groupId);
set("name", name);
set("ctry", country);
sortIndex = groupSortIndex;
}
}
}
My config :
gxt-1.1-alpha4
Windows XP
Host mode / EclipseThanks,
Yann.

darrellmeyer
18 Sep 2008, 11:15 AM
The issue is your sorter. Comment it out and try your code.