PDA

View Full Version : order group - grid grouping



fother
8 Aug 2009, 6:57 AM
in this example http://extjs.com/examples/#grouping how I can define the order for the GROUP?

for default I would like order industry DESC

regards

sven
8 Aug 2009, 8:03 AM
Extend groupingStore and override groupBy and applySort. There these things get setup

fother
8 Aug 2009, 8:44 AM
thanks sven.. I believe that this can be implemented by GXT Team in a GroupingStore class (of course that my code isnt the best but.... work fine :) )



private class XGroupingStore<M extends ModelData> extends GroupingStore<M> {

private String groupField;
private String sortGroupField;

public XGroupingStore() {
super();
}

@SuppressWarnings("unchecked")
public XGroupingStore(final ListLoader loader) {
super(loader);
}

@Override
protected boolean applyGrouping(final boolean alwaysFireChange) {
if (groupField != null) {
groupBy(groupField);
return true;
} else {
if (alwaysFireChange) {
fireEvent(DataChanged, createStoreEvent());
}
return false;
}
}

@Override
protected void applySort(final boolean supressEvent) {
super.applySort(supressEvent);
// sort by group after sorting
if (!isGroupOnSort() && !isRemoteGroup()) {
final String gs = getGroupState();
if (gs != null && !gs.equals(sortInfo.getSortField())) {
sortData(sortGroupField, SortDir.ASC);
}
}
}

@Override
public void clearGrouping() {
groupField = null;
if (isRemoteGroup()) {
if (config != null && config instanceof GroupingLoadConfig) {
((GroupingLoadConfig) config).setGroupBy("");
}
loader.load(config);
} else {
applySort(false);
fireEvent(DataChanged, createStoreEvent());
}
}

@Override
public String getGroupState() {
return isRemoteGroup() && groupField != null ? sortInfo != null ? sortInfo.getSortField() : null : groupField;
}

@Override
public void groupBy(final String field, final boolean forceRegroup) {
if (groupField != null && groupField.equals(field) && !forceRegroup) {
return;
}
groupField = field;
if (isRemoteGroup()) {
if (config != null && config instanceof GroupingLoadConfig) {
((GroupingLoadConfig) config).setGroupBy("");
} else {
final BaseGroupingLoadConfig c = new BaseGroupingLoadConfig();
c.setGroupBy(field);
config = c;
}
}

if (isGroupOnSort()) {
sort(field, null);
return;
}

if (isRemoteGroup()) {
loader.load(config);
} else {
final SortInfo se = sortInfo != null ? sortInfo : new SortInfo();
if (se.getSortField() != null && !se.getSortField().equals(field)) {
applySort(false);
} else {
sortData(field, null);
}
fireEvent(DataChanged, createStoreEvent());
}
}

public void setSortGroupField(final String sortGroupField) {
this.sortGroupField = sortGroupField;
}
}

fother
8 Aug 2009, 8:45 AM
the "red part" its what I change... you can post your opinion about this?

Arno.Nyhm
10 Aug 2009, 5:01 AM
to make it more generic you should also let the user set the sortig direction in setSortGroupField....

some more notes:

why did you overwrite some methods if you not change the code of the original method?
- applyGrouping
- clearGrouping
- groupBy