Total summary table (Ext GWT) : Table « GWT « Java






Total summary table (Ext GWT)

Total summary table (Ext GWT)
 

/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
 
 
package com.google.gwt.sample.hello.client;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupSummaryView;
import com.extjs.gxt.ui.client.widget.grid.SummaryColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.SummaryRenderer;
import com.extjs.gxt.ui.client.widget.grid.SummaryType;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

public class Hello implements EntryPoint {
  public void onModuleLoad() {
    RootPanel.get().add(new TotalsGridExample());
  }
}
class TotalsGridExample extends LayoutContainer {

  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FlowLayout(10));

    List<Task> tasks = getTasks();
    GroupingStore<Task> store = new GroupingStore<Task>();
    store.groupBy("project");
    store.add(tasks);

    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

    SummaryColumnConfig<Integer> desc = new SummaryColumnConfig<Integer>("description", "Task", 65);
    desc.setSummaryType(SummaryType.COUNT);
    desc.setSummaryRenderer(new SummaryRenderer() {
      public String render(Number value, Map<String, Number> data) {
        return value.intValue() > 1 ? "(" + value.intValue() + " Tasks)" : "(1 Task)";
      }
    });

    SummaryColumnConfig<Double> project = new SummaryColumnConfig<Double>("project", "Project", 55);
    SummaryColumnConfig<Double> due = new SummaryColumnConfig<Double>("due", "Due Date", 20);

    SummaryColumnConfig<Double> estimate = new SummaryColumnConfig<Double>("estimate", "Estimate", 20);
    estimate.setRenderer(new GridCellRenderer<Task>() {
      public String render(Task model, String property, ColumnData config, int rowIndex, int colIndex,
          ListStore<Task> store, Grid<Task> grid) {
        return model.get(property) + " hours";
      }
    });
    estimate.setSummaryType(SummaryType.SUM);
    estimate.setSummaryRenderer(new SummaryRenderer() {
      public String render(Number value, Map<String, Number> data) {
        return value.intValue() + " hours";
      }
    });
    estimate.setEditor(new CellEditor(new NumberField()));

    SummaryColumnConfig<Double> rate = new SummaryColumnConfig<Double>("rate", "Rate", 20);
    rate.setNumberFormat(NumberFormat.getCurrencyFormat());
    rate.setSummaryFormat(NumberFormat.getCurrencyFormat());
    rate.setSummaryType(SummaryType.AVG);
    rate.setAlignment(HorizontalAlignment.RIGHT);

    NumberField nf = new NumberField();
    nf.setAutoValidate(true);
    CellEditor ce = new CellEditor(nf);
    ce.setCancelOnEsc(true);
    rate.setEditor(ce);

    SummaryColumnConfig<Double> cost = new SummaryColumnConfig<Double>("cost", "Cost", 20);
    cost.setSummaryFormat(NumberFormat.getCurrencyFormat());
    cost.setSummaryType(new SummaryType<Double>() {
      @Override
      public Double render(Object v, ModelData m, String field, Map<String, Object> data) {
        if (v == null) {
          v = 0d;
        }
        Task task = (Task) m;
        return ((Double) v).doubleValue() + (task.getEstimate() * task.getRate());
      }

    });
    cost.setAlignment(HorizontalAlignment.RIGHT);
    cost.setRenderer(new GridCellRenderer<Task>() {
      public String render(Task model, String property, ColumnData config, int rowIndex, int colIndex,
          ListStore<Task> store, Grid<Task> grid) {
        Task task = (Task) model;
        return NumberFormat.getCurrencyFormat().format(task.getRate() * task.getEstimate());
      }
    });

    columns.add(desc);
    columns.add(project);
    columns.add(due);
    columns.add(estimate);
    columns.add(rate);
    columns.add(cost);
    ColumnModel cm = new ColumnModel(columns);

    GroupSummaryView summary = new GroupSummaryView();
    summary.setForceFit(true);
    summary.setShowGroupedColumn(false);

    EditorGrid<Task> grid = new EditorGrid<Task>(store, cm);
    grid.setBorders(true);
    grid.setView(summary);
    grid.getView().setShowDirtyCells(false);

    ContentPanel panel = new ContentPanel();
    panel.setHeading("Sponsored Projects");
    //panel.setIcon(Resources.ICONS.table());
    panel.setCollapsible(true);
    panel.setFrame(true);
    panel.setSize(800, 450);
    panel.setLayout(new FitLayout());
    panel.add(grid);
    add(panel);
  }
  public static List<Task> getTasks() {
    List<Task> tasks = new ArrayList<Task>();
    tasks.add(new Task(100, "Ext Forms: Field Anchoring", 112,
        "Integrate 2.0 Forms with 2.0 Layouts", 6, 150, "06/24/2007"));
    tasks.add(new Task(100, "Ext Forms: Field Anchoring", 113, "Implement AnchorLayout",
        4, 150, "06/25/2007"));
    tasks.add(new Task(100, "Ext Forms: Field Anchoring", 114,
        "Add support for multiple types of anchors", 4, 150, "06/27/2007"));
    tasks.add(new Task(100, "Ext Forms: Field Anchoring", 115, "Testing and debugging",
        8, 0, "06/29/2007"));

    tasks.add(new Task(101, "Ext Grid: Single-level Grouping", 101,
        "Add required rendering 'hooks' to GridView", 6, 100, "07/01/2007"));
    tasks.add(new Task(101, "Ext Grid: Single-level Grouping", 102,
        "Extend GridView and override rendering functions", 4, 0, "07/03/2007"));
    tasks.add(new Task(101, "Ext Grid: Single-level Grouping", 103,
        "Extend Store with grouping functionality", 4, 100, "07/04/2007"));
    tasks.add(new Task(101, "Ext Grid: Single-level Grouping", 121,
        "Default CSS Styling", 2, 1000, "07/05/2007"));
    tasks.add(new Task(101, "Ext Grid: Single-level Grouping", 104,
        "Testing and debugging", 6, 100, "07/06/2007"));

    tasks.add(new Task(102, "Ext Grid: Summary Rows", 105, "Ext Grid plugin integration",
        4, 125, "07/01/2007"));
    tasks.add(new Task(102, "Ext Grid: Summary Rows", 106,
        "Summary creation during rendering phase", 6, 125, "07/02/2007"));
    tasks.add(new Task(102, "Ext Grid: Summary Rows", 107,
        "Dynamic summary updates in editor grids", 6, 125, "07/05/2007"));
    tasks.add(new Task(102, "Ext Grid: Summary Rows", 108, "Remote summary integration",
        4, 125, "07/05/2007"));
    tasks.add(new Task(102, "Ext Grid: Summary Rows", 109,
        "Summary renderers and calculators", 4, 125, "07/06/2007"));
    tasks.add(new Task(102, "Ext Grid: Summary Rows", 110,
        "Integrate summaries with GroupingView", 10, 125, "07/11/2007"));
    tasks.add(new Task(102, "Ext Grid: Summary Rows", 111, "Testing and debugging", 8,
        125, "07/15/2007"));
    return tasks;
  }
}
class Task extends BaseModelData {

  public Task(int id, String project, int taskId, String desc, double estimate, double rate,
      String due) {
    set("id", id);
    set("project", project);
    set("taskId", taskId);
    set("description", desc);
    set("estimate", estimate);
    set("rate", rate);
    set("due", due);
  }

  public Double getEstimate() {
    return (Double) get("estimate");
  }

  public double getRate() {
    return (Double) get("rate");
  }

}

   
  








Ext-GWT.zip( 4,297 k)

Related examples in the same category

1.Absolute Table
2.SortableTable Widget for GWT
3.Dynamic Table
4.Set up drag and drop between ListGrids (Smart GWT)Set up drag and drop between ListGrids (Smart GWT)
5.Adding Selection listener to ListGrid (Smart GWT)Adding Selection listener to ListGrid (Smart GWT)
6.Menus support all the drag and drop behaviors supported by grids (Smart GWT)Menus support all the drag and drop behaviors supported by grids (Smart GWT)
7.Single column ListGrid (Smart GWT)Single column ListGrid (Smart GWT)
8.extends ListGridRecord to create Record for ListGrid (Smart GWT)extends ListGridRecord to create Record for ListGrid (Smart GWT)
9.Grid Form Add Sample (Smart GWT)Grid Form Add Sample (Smart GWT)
10.Grid Form Update Sample (Smart GWT)Grid Form Update Sample (Smart GWT)
11.Nested Form in a Grid Sample (Smart GWT)Nested Form in a Grid Sample (Smart GWT)
12.Grid Simple Freeze Sample (Smart GWT)Grid Simple Freeze Sample (Smart GWT)
13.Grid Dynamic Freeze Sample (Smart GWT)Grid Dynamic Freeze Sample (Smart GWT)
14.Table Autofit Filter Sample (Smart GWT)Table Autofit Filter Sample (Smart GWT)
15.Table selection event (Smart GWT)Table selection event (Smart GWT)
16.Table Header Hover Tips Sample (Smart GWT)Table Header Hover Tips Sample (Smart GWT)
17.Table with Multiple Selection Sample (Smart GWT)Table with Multiple Selection Sample (Smart GWT)
18.Table record clicked event (Smart GWT)Table record clicked event (Smart GWT)
19.Table record double-clicked event (Smart GWT)Table record double-clicked event (Smart GWT)
20.Table row context click handler (Smart GWT)Table row context click handler (Smart GWT)
21.Table mouse hover event (Smart GWT)Table mouse hover event (Smart GWT)
22.Table columns are sorted as date, number, and calculated number values, respectively (Smart GWT)Table columns are sorted as date, number, and calculated number values, respectively (Smart GWT)
23.Table cell hover tooltip (Smart GWT)Table cell hover tooltip (Smart GWT)
24.Show/hide table header (Smart GWT)Show/hide table header (Smart GWT)
25.extends ListGrid (Smart GWT)extends ListGrid (Smart GWT)
26.Drag to reorder table rows (Smart GWT)Drag to reorder table rows (Smart GWT)
27.Add to / clear ListGrid (Smart GWT)Add to / clear ListGrid (Smart GWT)
28.Grid Dependent Selects Sample (Smart GWT)Grid Dependent Selects Sample (Smart GWT)
29.Table Single Select Sample (Smart GWT)Table Single Select Sample (Smart GWT)
30.Nested Grid in another Grid cell Sample (Smart GWT)Nested Grid in another Grid cell Sample (Smart GWT)
31.Formula Summary Builder Sample (Smart GWT)Formula Summary Builder Sample (Smart GWT)
32.Add paging support for a local collection of models (Ext GWT)Add paging support for a local collection of models (Ext GWT)
33.Load from Php and add to table with LiveGridView (Ext GWT)Load from Php and add to table with LiveGridView (Ext GWT)
34.Using BufferView to create buffered grid (Ext GWT)Using BufferView to create buffered grid (Ext GWT)