001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.client.data;
009:
010: import com.google.gwt.core.client.JavaScriptObject;
011: import com.gwtext.client.core.UrlParam;
012: import com.gwtext.client.util.JavaScriptObjectHelper;
013:
014: /**
015: * A specialized store implementation that provides for grouping records by one of the available fields.
016: */
017: public class GroupingStore extends Store {
018:
019: /**
020: * Construct a new GroupingStore.
021: */
022: public GroupingStore() {
023: }
024:
025: /**
026: * Create a Store using the specified {@link RecordDef}. Data can be added to the Store using
027: * {@link #add(Record)}
028: *
029: * @param recordDef the record def
030: */
031: public GroupingStore(RecordDef recordDef) {
032: super (recordDef);
033: }
034:
035: /**
036: * Create a Store using the specified {@link Reader}.
037: *
038: * @param reader the reader
039: */
040: public GroupingStore(Reader reader) {
041: super (reader);
042: }
043:
044: /**
045: * Create a Store using the specified {@link com.gwtext.client.data.DataProxy} and {@link Reader}.
046: *
047: * @param dataProxy the data proxy
048: * @param reader the reader
049: */
050: public GroupingStore(DataProxy dataProxy, Reader reader) {
051: super (dataProxy, reader);
052: }
053:
054: /**
055: * Create a Store using the specified {@link com.gwtext.client.data.DataProxy} and {@link Reader}.
056: *
057: * @param dataProxy the data proxy
058: * @param reader the reader
059: * @param remoteSort true to enable remote sort of the data
060: */
061: public GroupingStore(DataProxy dataProxy, Reader reader,
062: boolean remoteSort) {
063: super (dataProxy, reader, remoteSort);
064: }
065:
066: /**
067: * Create a Store using the specified configuration.
068: *
069: * @param dataProxy the data proxy
070: * @param reader the reader
071: * @param baseParams base params which are to be sent as parameters on any HTTP request. Used only for Http based proxies.
072: * @param initialSortState the initial sort field name and direction
073: * @param remoteSort true to enable remote sort
074: */
075: public GroupingStore(DataProxy dataProxy, Reader reader,
076: UrlParam[] baseParams, SortState initialSortState,
077: boolean remoteSort) {
078: super (dataProxy, reader, baseParams, initialSortState,
079: remoteSort);
080: }
081:
082: native JavaScriptObject create(JavaScriptObject config) /*-{
083: return new $wnd.Ext.data.GroupingStore(config);
084: }-*/;
085:
086: /**
087: * Clears any existing grouping and refreshes the data using the default sort.
088: */
089: public native void clearGrouping() /*-{
090: var gstore = this.@com.gwtext.client.core.JsObject::getJsObj()();
091: gstore.clearGrouping();
092: }-*/;
093:
094: /**
095: * Groups the data by the specified field.
096: *
097: * @param field The field name by which to sort the store's data
098: */
099: public native void groupBy(String field) /*-{
100: var gstore = this.@com.gwtext.client.core.JsObject::getJsObj()();
101: gstore.groupBy(field);
102: }-*/;
103:
104: /**
105: * Groups the data by the specified field.
106: *
107: * @param field The field name by which to sort the store's data
108: * @param forceRegroup true to force the group to be refreshed even if the field passed in is the same as the current
109: * grouping field, false to skip grouping on the same field (defaults to false)
110: */
111: public native void groupBy(String field, boolean forceRegroup) /*-{
112: var gstore = this.@com.gwtext.client.core.JsObject::getJsObj()();
113: gstore.groupBy(field, forceRegroup);
114: }-*/;
115:
116: //config options
117: /**
118: * The field name by which to sort the store's data (defaults to '').
119: *
120: * @param groupField the group field
121: */
122: public void setGroupField(String groupField) {
123: JavaScriptObjectHelper.setAttribute(configJS, "groupField",
124: groupField);
125: }
126:
127: /**
128: * True to sort the data on the grouping field when a grouping operation occurs,
129: * false to sort based on the existing sort info (defaults to false).
130: *
131: * @param groupOnSort true to group on sort
132: */
133: public void setGroupOnSort(boolean groupOnSort) {
134: JavaScriptObjectHelper.setAttribute(configJS, "groupOnSort",
135: groupOnSort);
136: }
137:
138: /**
139: * True if the grouping should apply on the server side, false if it is local only (defaults to false).
140: * If the grouping is local, it can be applied immediately to the data. If it is remote, then it will simply act as
141: * a helper, automatically sending the grouping field name as the 'groupBy' param with each XHR call.
142: *
143: * @param remoteGroup true if the grouping should apply on the server side
144: */
145: public void setRemoteGroup(boolean remoteGroup) {
146: JavaScriptObjectHelper.setAttribute(configJS, "remoteGroup",
147: remoteGroup);
148: }
149: }
|