Using GroupingView to display grouped grid data (Ext GWT) : Table Grouping « GWT « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JDK 6
25.JNDI LDAP
26.JPA
27.JSP
28.JSTL
29.Language Basics
30.Network Protocol
31.PDF RTF
32.Reflection
33.Regular Expressions
34.Scripting
35.Security
36.Servlets
37.Spring
38.Swing Components
39.Swing JFC
40.SWT JFace Eclipse
41.Threads
42.Tiny Application
43.Velocity
44.Web Services SOA
45.XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Java » GWT » Table GroupingScreenshots 
Using GroupingView to display grouped grid data (Ext GWT)
Using GroupingView to display grouped grid data (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.Date;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer;
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData;
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
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.DateTimeFormat;
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 GroupingGridExample());
  }
}
class GroupingGridExample extends LayoutContainer {

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

    setLayout(new FlowLayout(10));

    GroupingStore<Stock> store = new GroupingStore<Stock>();
    store.add(getCompanies());
    store.groupBy("industry");

    ColumnConfig company = new ColumnConfig("name""Company"60);
    ColumnConfig price = new ColumnConfig("open""Price"20);
    ColumnConfig change = new ColumnConfig("change""Change"20);
    ColumnConfig industry = new ColumnConfig("industry""Industry"20);
    ColumnConfig last = new ColumnConfig("date""Last Updated"20);
    last.setDateTimeFormat(DateTimeFormat.getFormat("MM/dd/y"));

    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
    config.add(company);
    config.add(price);
    config.add(change);
    config.add(industry);
    config.add(last);

    final ColumnModel cm = new ColumnModel(config);

    GroupingView view = new GroupingView();
    view.setShowGroupedColumn(false);
    view.setForceFit(true);
    view.setGroupRenderer(new GridGroupRenderer() {
      public String render(GroupColumnData data) {
        String f = cm.getColumnById(data.field).getHeader();
        String l = data.models.size() == "Item" "Items";
        return f + ": " + data.group + " (" + data.models.size() " " + l + ")";
      }
    });

    Grid<Stock> grid = new Grid<Stock>(store, cm);
    grid.setView(view);
    grid.setBorders(true);

    ContentPanel panel = new ContentPanel();
    panel.setHeading("Grouping Example");
   // panel.setIcon(Resources.ICONS.table());
    panel.setCollapsible(true);
    panel.setFrame(true);
    panel.setSize(700450);
    panel.setLayout(new FitLayout());
    panel.add(grid);

    add(panel);
  }

  public static List<Stock> getCompanies() {
    DateTimeFormat f = DateTimeFormat.getFormat("M/d h:mma");
    List<Stock> stocks = new ArrayList<Stock>();
    stocks.add(new Stock("3m Co"71.720.020.03, f.parse("4/2 12:00am"),
        "Manufacturing"));
    stocks.add(new Stock("Alcoa Inc"29.010.421.47, f.parse("4/1 12:00am"),
        "Manufacturing"));
    stocks.add(new Stock("Altria Group Inc"83.810.280.34, f.parse("4/3 12:00am"),
        "Manufacturing"));
    stocks.add(new Stock("American Express Company"52.550.010.02,
        f.parse("4/8 12:00am")"Finance"));
    stocks.add(new Stock("American International Group, Inc."64.130.310.49,
        f.parse("4/1 12:00am")"Services"));
    stocks.add(new Stock("AT&T Inc."31.61, -0.48, -1.54, f.parse("4/8 12:00am"),
        "Services"));
    stocks.add(new Stock("Boeing Co."75.430.530.71, f.parse("4/8 12:00am"),
        "Manufacturing"));
    stocks.add(new Stock("Caterpillar Inc."67.270.921.39, f.parse("4/1 12:00am"),
        "Services"));
    stocks.add(new Stock("Citigroup, Inc."49.370.020.04, f.parse("4/4 12:00am"),
        "Finance"));
    stocks.add(new Stock("E.I. du Pont de Nemours and Company"40.480.511.28,
        f.parse("4/1 12:00am")"Manufacturing"));
    stocks.add(new Stock("Exxon Mobil Corp"68.1, -0.43, -0.64, f.parse("4/3 12:00am"),
        "Manufacturing"));
    stocks.add(new Stock("General Electric Company"34.14, -0.08, -0.23,
        f.parse("4/3 12:00am")"Manufacturing"));
    stocks.add(new Stock("General Motors Corporation"30.271.093.74,
        f.parse("4/3 12:00am")"Automotive"));
    stocks.add(new Stock("Hewlett-Packard Co."36.53, -0.03, -0.08,
        f.parse("4/3 12:00am")"Computer"));
    stocks.add(new Stock("Honeywell Intl Inc"38.770.050.13, f.parse("4/3 12:00am"),
        "Manufacturing"));
    stocks.add(new Stock("Intel Corporation"19.880.311.58, f.parse("4/2 12:00am"),
        "Computer"));
    stocks.add(new Stock("International Business Machines"81.410.440.54,
        f.parse("4/1 12:00am")"Computer"));
    stocks.add(new Stock("Johnson & Johnson"64.720.060.09, f.parse("4/2 12:00am"),
        "Medical"));
    stocks.add(new Stock("JP Morgan & Chase & Co"45.730.070.15,
        f.parse("4/2 12:00am")"Finance"));
    stocks.add(new Stock("McDonald\"s Corporation"36.760.862.40,
        f.parse("4/2 12:00am")"Food"));
    stocks.add(new Stock("Merck & Co., Inc."40.960.411.01, f.parse("4/2 12:00am"),
        "Medical"));
    stocks.add(new Stock("Microsoft Corporation"25.840.140.54,
        f.parse("4/2 12:00am")"Computer"));
    stocks.add(new Stock("Pfizer Inc"27.960.41.45, f.parse("4/8 12:00am"),
        "Services"));
    stocks.add(new Stock("The Coca-Cola Company"45.070.260.58,
        f.parse("4/1 12:00am")"Food"));
    stocks.add(new Stock("The Home Depot, Inc."34.640.351.02,
        f.parse("4/8 12:00am")"Retail"));
    stocks.add(new Stock("The Procter & Gamble Company"61.910.010.02,
        f.parse("4/1 12:00am")"Manufacturing"));
    stocks.add(new Stock("United Technologies Corporation"63.260.550.88,
        f.parse("4/1 12:00am")"Computer"));
    stocks.add(new Stock("Verizon Communications"35.570.391.11,
        f.parse("4/3 12:00am")"Services"));
    stocks.add(new Stock("Wal-Mart Stores, Inc."45.450.731.63,
        f.parse("4/3 12:00am")"Retail"));
    stocks.add(new Stock("Walt Disney Company (The) (Holding Company)"29.890.24,
        0.81, f.parse("4/1 12:00am")"Services"));
    return stocks;
  }
}
class Stock extends BaseModel {

  public Stock() {
  }

  public Stock(String name, String symbol, double open, double last) {
    set("name", name);
    set("symbol", symbol);
    set("open", open);
    set("last", last);
    set("date"new Date());
    set("change", last - open);
  }

  public Stock(String name, double open, double change, double pctChange, Date date, String industry) {
    set("name", name);
    set("open", open);
    set("change", change);
    set("percentChange", pctChange);
    set("date", date);
    set("industry", industry);
  }

  public String getIndustry() {
    return get("industry");
  }

  public void setIndustry(String industry) {
    set("industry", industry);
  }

  public Date getLastTrans() {
    return (Dateget("date");
  }

  public String getName() {
    return (Stringget("name");
  }

  public String getSymbol() {
    return (Stringget("symbol");
  }

  public double getOpen() {
    Double open = (Doubleget("open");
    return open.doubleValue();
  }

  public double getLast() {
    Double open = (Doubleget("last");
    return open.doubleValue();
  }

  public double getChange() {
    return getLast() - getOpen();
  }

  public double getPercentChange() {
    return getChange() / getOpen();
  }

  public String toString() {
    return getName();
  }

}

   
  
Ext-GWT.zip( 4,297 k)
Related examples in the same category
1.Grid with Custom Grouping Sample (Smart GWT)Grid with Custom Grouping Sample (Smart GWT)
2.Grid with Dynamic Grouping Sample (Smart GWT)Grid with Dynamic Grouping Sample (Smart GWT)
3.Grid Grouped Editing Sample (Smart GWT)Grid Grouped Editing Sample (Smart GWT)
4.Column grouping with Widget (Ext GWT)Column grouping with Widget (Ext GWT)
5.Three-level column grouping (Ext GWT)Three-level column grouping (Ext GWT)
6.Using GroupingStore to load grouped grid data (Ext GWT)Using GroupingStore to load grouped grid data (Ext GWT)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.