package com.smartgwt.sample.showcase.client.grid; import java.util.HashSet; import java.util.Set; import com.google.gwt.i18n.client.NumberFormat; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.GroupStartOpen; import com.smartgwt.client.types.RecordSummaryFunctionType; import com.smartgwt.client.types.SummaryFunctionType; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.grid.CellFormatter; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.grid.ListGridSummaryField; import com.smartgwt.client.widgets.grid.SummaryFunction; import com.smartgwt.sample.showcase.client.PanelFactory; import com.smartgwt.sample.showcase.client.ShowcasePanel; import com.smartgwt.sample.showcase.client.data.OrderItem; import com.smartgwt.sample.showcase.client.data.OrderItemLocalDS; public class GridSummariesSample extends ShowcasePanel { private static final String DESCRIPTION = "
ListGrids support displaying summaries of the current data set in various ways:
" + "Fields from individual records can be summarized into a single field value. In this example the \"Total\" " + "field displays a summary value calculated by multiplying the \"Quantity\" and \"Price\" fields.
" + "Summaries can also be displayed for multiple records. This example shows a summary row at the end of each " + "group in the grid as well as an overall summary row with information about every record in the grid. Note that in " + "addition to standard summary functions such as \"sum\" to generate a total, or \"count\" to generate a count of records, " + "completely custom functions may be used. This is demonstrated in the \"Category\" field where a custom function determines " + "how many categories exist in this dataset.
"; public static class Factory implements PanelFactory { private String id; public ShowcasePanel create() { GridSummariesSample panel = new GridSummariesSample(); id = panel.getID(); return panel; } public String getID() { return id; } public String getDescription() { return DESCRIPTION; } } public Canvas getViewPanel() { DataSource dataSource = OrderItemLocalDS.getInstance(); ListGridField orderIdField = new ListGridField("orderID"); orderIdField.setIncludeInRecordSummary(false); orderIdField.setSummaryFunction(SummaryFunctionType.COUNT); ListGridField itemDescriptionField = new ListGridField("itemDescription"); ListGridField categoryField = new ListGridField("category"); categoryField.setShowGridSummary(true); categoryField.setSummaryFunction(new SummaryFunction() { public Object getSummaryValue(Record[] records, ListGridField field) { Set